﻿using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Text;
using Von.Library;
using Von.Web.Models;

namespace Von.Web.Datas
{
    public static class Statement
    {
        public static ApplicationDefinationBase App { get; set; }
        public static SqlConnection CreateConnection() { return (SqlConnection)App.DBAccession.CreateConnection(); }
        public static SqlTransaction BeginDBTrans() { return (SqlTransaction)App.DBAccession.BeginDBTrans(); }
        public static SqlCommand InitCommand(string sqlText, DbTransaction DBTrans) {
            return (SqlCommand)App.DBAccession.InitCommand(sqlText, DBTrans); }
        public static string Owner { get { return App.Owner; } }
        public static string Qualifier { get { return App.Qualifier; } }
    }
    /// <summary>
    /// Sql server 数据库基本调用控制器
    /// </summary>
    public abstract class SqlApplicationDBAccessionBase : StatementDBAccessionBase
    {
        #region private declaration
        private class DBTableCondition
        {
            public string tableCode { get; set; }
            public char tableAlias { get; set; }
            public string joinCondition { get; set; }
            public VonTableDefination tbl { get; set; }
        }
        /// <summary>
        /// 获取层级括号
        /// </summary>
        /// <param name="num">层级数量，正数为左括号，负数为右括号</param>
        /// <returns></returns>
        private string getBrackets(int num)
        {
            if (num > 0) return "((((((((((((((((((((((((((((((((((".Substring(0, num);
            if (num < 0) return "))))))))))))))))))))))))))))))))))".Substring(0, -num);
            return "";
        }
        /// <summary>
        /// 将关联表集合写入查询语句的FROM中
        /// </summary>
        /// <param name="tbls">表集合</param>
        /// <param name="sbFrom">FROM语句，包含JOIN</param>
        private void tablesToJoin(List<DBTableCondition> tbls, StringBuilder sbFrom)
        {
            foreach (var t in tbls)
            {
                sbFrom.Append(sbFrom.Length > 0 ? " JOIN " : " FROM ");
                sbFrom.Append(AppDefination.Owner);
                sbFrom.Append(AppDefination.Qualifier);
                sbFrom.Append(t.tableCode);
                sbFrom.Append(" ");
                sbFrom.Append(t.tableAlias);
                sbFrom.Append((string.IsNullOrEmpty(t.joinCondition) ? " " : " ON " + t.joinCondition));
            }
        }
        private string addParam(SqlCommand cmd, ref int paramIdx, VonDefinationField field, object data)
        {
            string paramName = "P" + paramIdx.ToString();
            paramIdx++;
            newSqlParameter(cmd, paramName, (SqlDbType)field.fieldType, data);
            return paramName;
        }
        /// <summary>
        /// 将关联信息写入表结合中，同时将关联查询字段写入查询字段集合
        /// </summary>
        /// <param name="cmd">执行SQL的命令单元</param>
        /// <param name="alias">当前表节点对应的别名字母</param>
        /// <param name="paramIdx">整个查询条件的参数序号</param>
        /// <param name="selection">设置的选择器</param>
        /// <param name="tbls">已经建立的设计到查询的表清单</param>
        /// <param name="sbSelect">SQL select 语句</param>
        /// <param name="sbWhere">SQL where 语句</param>
        /// <param name="sbOrder">SQL order 语句</param>
        private void analyzeSelection(SqlCommand cmd, ref char alias, ref int paramIdx, JObject selection, List<DBTableCondition> tbls, StringBuilder sbSelect, StringBuilder sbWhere, StringBuilder sbOrder)
        {
            // 获取当前表的结构定义
            VonTableDefination tb = tables.FirstOrDefault(t => t.tableCode.Equals(selection["TableCode"].ToString(), StringComparison.OrdinalIgnoreCase));
            // 是否拥有强制关联设定
            if (tbls.Count == 0)
            {
                #region 主表，直接添加到条件语句中，以后可以生成 FROM 语句
                tbls.Add(new DBTableCondition()
                {
                    tableCode = selection["TableCode"].ToString(),
                    tableAlias = alias,
                    tbl = tb
                });
                #endregion
            }
            else if (string.IsNullOrEmpty(selection["refField"].ToString()))
            {
                #region 从表，在已查询的表集合中，查找关联关系
                foreach (var tbl in tbls)
                {
                    VonTableReference refs = tbl.tbl.Reference.FirstOrDefault(r => r.destTable.Equals(selection["TableCode"].ToString(), StringComparison.OrdinalIgnoreCase));
                    if (refs != null)
                    {
                        // 查找到合适的关联关系后，增加关联关系条件
                        tbls.Add(new DBTableCondition()
                        {
                            tableCode = selection["TableCode"].ToString(),
                            tableAlias = alias,
                            joinCondition = tbl.tableAlias + "." + refs.srcField + "=" + alias + "." + refs.destField,
                            tbl = tb
                        });
                        break;
                    }
                }
                #endregion
            }
            else
            {
                #region 从表，已人工指定关联关系，<关联字段>=<关联表名>.<关联表关联字段>，如：GameIdx=Match.ID
                string[] s = selection["refField"].ToString().Split(new char[] { '.', '=' });
                DBTableCondition dest = tbls.FirstOrDefault(d => d.tableCode.Equals(s[1], StringComparison.OrdinalIgnoreCase));
                if (tb == null) return;
                tbls.Add(new DBTableCondition()
                {
                    tableCode = selection["TableCode"].ToString(),
                    tableAlias = alias,
                    joinCondition = dest.tableAlias + "." + s[2] + "=" + alias + "." + s[0],
                    tbl = tb
                });
                #endregion
            }
            if (selection["Fields"] != null && !string.IsNullOrEmpty(selection["Fields"].ToString()))
            {
                #region 添加要查询的内容，支持数量限制，如果第一个查询内容是数字，则表示是要查询的数量限制，系统会以 top num 进行控制
                string[] arrFields = selection["Fields"].ToString().Split(',');
                int count = 0;
                if (int.TryParse(arrFields[0], out count))  //如果字段为数字的话，则表示是查询内容的数量限制
                {
                    sbSelect.Append("top ");
                    sbSelect.Append(count);
                    sbSelect.Append(" ");
                }
                for (int i = (count == 0) ? 0 : 1; i < arrFields.Length; i++)
                {
                    string s = arrFields[i].Trim();
                    if (s == "*") { sbSelect.Append(alias); sbSelect.Append(".*"); }
                    else if (tb.Fields.FirstOrDefault(f => f.fieldCode.Equals(s, StringComparison.OrdinalIgnoreCase)) == null) continue;
                    else { sbSelect.Append(alias); sbSelect.Append("."); sbSelect.Append(s); sbSelect.Append(","); }
                }
                #endregion
            }
            #region 添加排序字段控制，系统支持排序方式控制，即字段名加正序倒序控制，如：displayOrder ASC,Speed DESC
            if (sbOrder != null)
            {
                if (selection["orderFields"] != null && !string.IsNullOrEmpty(selection["orderFields"].ToString()))
                {
                    //自定义排序
                    string[] arrFields = selection["orderFields"].ToString().Split(',');
                    foreach (var s in arrFields)
                    {
                        string[] arrField = selection["orderFields"].ToString().Split(' ');
                        if (tb.Fields.FirstOrDefault(f => f.fieldCode.Equals(arrField[0], StringComparison.OrdinalIgnoreCase)) == null) continue;
                        else { sbOrder.Append(alias); sbOrder.Append("."); sbOrder.Append(s); sbOrder.Append(","); }
                    }
                }
                else if (!string.IsNullOrEmpty(tb.orderField))
                {
                    //该表拥有自己的排序字段
                    sbOrder.Append(alias); sbOrder.Append("."); sbOrder.Append(tb.orderField); sbOrder.Append(",");
                }
            }
            #endregion
            #region 获取查询条件内容SQL预计及参数设置，<字段名>=<值>
            if (selection["conditions"] != null && ((JArray)selection["conditions"]).Count > 0)
            {
                int level = 0;
                foreach (var c in (JArray)selection["conditions"])
                {
                    VonDefinationField field = tb.Fields.FirstOrDefault(f => f.fieldCode.Equals(c["FieldName"].ToString(), StringComparison.OrdinalIgnoreCase));
                    if (field == null) continue;
                    string s = "";
                    switch (c["Condition"].ToString())
                    {
                        case "不等于": s = alias + "." + c["FieldName"].ToString() + "<>@" + addParam(cmd, ref paramIdx, field, c["Data"].ToString()); break;
                        case "等于": s = alias + "." + c["FieldName"].ToString() + "=@" + addParam(cmd, ref paramIdx, field, c["Data"].ToString()); break;
                        case "大于": s = alias + "." + c["FieldName"].ToString() + ">@" + addParam(cmd, ref paramIdx, field, c["Data"].ToString()); break;
                        case "大于等于": s = alias + "." + c["FieldName"].ToString() + ">=@" + addParam(cmd, ref paramIdx, field, c["Data"].ToString()); break;
                        case "小于": s = alias + "." + c["FieldName"].ToString() + "<@" + addParam(cmd, ref paramIdx, field, c["Data"].ToString()); break;
                        case "小于等于": s = alias + "." + c["FieldName"].ToString() + "<=@" + addParam(cmd, ref paramIdx, field, c["Data"].ToString()); break;
                        case "前近似": s = alias + "." + c["FieldName"].ToString() + " LIKE '%' + @" + addParam(cmd, ref paramIdx, field, c["Data"].ToString()); break;
                        case "后近似": s = alias + "." + c["FieldName"].ToString() + " LIKE @" + addParam(cmd, ref paramIdx, field, c["Data"].ToString()) + " + '%'"; break;
                        case "前后近似": s = alias + "." + c["FieldName"].ToString() + " LIKE '%' + @" + addParam(cmd, ref paramIdx, field, c["Data"].ToString()) + " + '%'"; break;
                        case "在其中":
                            string[] datas = c["Data"].ToString().Split(',');
                            s = alias + "." + c["FieldName"].ToString() + " in (";
                            foreach (var ds in datas)
                            {
                                s += "@" + addParam(cmd, ref paramIdx, field, ds) + ",";
                            }
                            s = s.Trim(',') + ")";
                            break;
                        case "范围":
                            string[] bs = c["Data"].ToString().Split(',');
                            s = alias + "." + c["FieldName"].ToString() + " between @" + addParam(cmd, ref paramIdx, field, bs[0]) + " AND @" + addParam(cmd, ref paramIdx, field, bs[1]);
                            break;
                    }
                    if (sbWhere.Length == 0) { sbWhere.Append(getBrackets((int)c["Level"] - level)); sbWhere.Append(s); }
                    else switch (c["Connector"].ToString())
                        {
                            case "NONE": sbWhere.Append(getBrackets((int)c["Level"] - level)); sbWhere.Append(s); break;
                            case "AND": sbWhere.Append(" AND "); sbWhere.Append(getBrackets((int)c["Level"] - level)); sbWhere.Append(s); break;
                            case "OR": sbWhere.Append(" OR "); sbWhere.Append(getBrackets((int)c["Level"] - level)); sbWhere.Append(s); break;
                        }
                    level = (int)c["Level"];
                }
                sbWhere.Append(getBrackets(-level));
            }
            #endregion
            alias++;
            if (selection["Joins"] != null && ((JArray)selection["Joins"]).Count > 0)
            {
                foreach (var j in (JArray)selection["Joins"])
                {
                    analyzeSelection(cmd, ref alias, ref paramIdx, (JObject)j, tbls, sbSelect, sbWhere, sbOrder);
                }
            }
        }
        /// <summary>
        /// 将关联信息写入表结合中，同时将关联查询字段写入查询字段集合
        /// </summary>
        /// <param name="cmd">执行SQL的命令单元</param>
        /// <param name="alias">当前表节点对应的别名字母</param>
        /// <param name="paramIdx">整个查询条件的参数序号</param>
        /// <param name="selection">设置的选择器</param>
        /// <param name="tbls">已经建立的设计到查询的表清单</param>
        /// <param name="sbSelect">SQL select 语句</param>
        /// <param name="sbWhere">SQL where 语句</param>
        /// <param name="sbOrder">SQL order 语句</param>
        private void analyzeSelection(SqlCommand cmd, ref char alias, ref int paramIdx, DBSelection selection, List<DBTableCondition> tbls, StringBuilder sbSelect, StringBuilder sbWhere, StringBuilder sbOrder)
        {
            // 获取当前表的结构定义
            VonTableDefination tb = tables.FirstOrDefault(t => t.tableCode.Equals(selection.TableCode, StringComparison.OrdinalIgnoreCase));
            // 是否拥有强制关联设定
            if (tbls.Count == 0)
            {
                #region 主表，直接添加到条件语句中，以后可以生成 FROM 语句
                tbls.Add(new DBTableCondition()
                {
                    tableCode = selection.TableCode,
                    tableAlias = alias,
                    tbl = tb
                });
                #endregion
            }
            else if (string.IsNullOrEmpty(selection.refField))
            {
                #region 从表，在已查询的表集合中，查找关联关系
                foreach (var tbl in tbls)
                {
                    VonTableReference refs = tbl.tbl.Reference.FirstOrDefault(r => r.destTable.Equals(selection.TableCode, StringComparison.OrdinalIgnoreCase));
                    if (refs != null)
                    {
                        // 查找到合适的关联关系后，增加关联关系条件
                        tbls.Add(new DBTableCondition()
                        {
                            tableCode = selection.TableCode,
                            tableAlias = alias,
                            joinCondition = tbl.tableAlias + "." + refs.srcField + "=" + alias + "." + refs.destField,
                            tbl = tb
                        });
                        break;
                    }
                }
                #endregion
            }
            else
            {
                #region 从表，已人工指定关联关系，<关联字段>=<关联表名>.<关联表关联字段>，如：GameIdx=Match.ID
                string[] s = selection.refField.Split(new char[] { '.', '=' });
                DBTableCondition dest = tbls.FirstOrDefault(d => d.tableCode.Equals(s[1], StringComparison.OrdinalIgnoreCase));
                if (tb == null) return;
                tbls.Add(new DBTableCondition()
                {
                    tableCode = selection.TableCode,
                    tableAlias = alias,
                    joinCondition = dest.tableAlias + "." + s[2] + "=" + alias + "." + s[0],
                    tbl = tb
                });
                #endregion
            }
            if (!string.IsNullOrEmpty(selection.Fields))
            {
                #region 添加要查询的内容，支持数量限制，如果第一个查询内容是数字，则表示是要查询的数量限制，系统会以 top num 进行控制
                string[] arrFields = selection.Fields.Split(',');
                int count = 0;
                if (int.TryParse(arrFields[0], out count))  //如果字段为数字的话，则表示是查询内容的数量限制
                {
                    sbSelect.Append("top ");
                    sbSelect.Append(count);
                    sbSelect.Append(" ");
                }
                for (int i = (count == 0) ? 0 : 1; i < arrFields.Length; i++)
                {
                    string s = arrFields[i].Trim().Split(' ')[0];
                    if (s == "*") { sbSelect.Append(alias); sbSelect.Append(".*"); }
                    else if(s.StartsWith("'")) {sbSelect.Append(arrFields[i].Trim()); sbSelect.Append(","); }
                    else if (tb.Fields.FirstOrDefault(f => f.fieldCode.Equals(s, StringComparison.OrdinalIgnoreCase)) == null) continue;
                    else { sbSelect.Append(alias); sbSelect.Append("."); sbSelect.Append(arrFields[i].Trim()); sbSelect.Append(","); }
                }
                #endregion
            }
            #region 添加排序字段控制，系统支持排序方式控制，即字段名加正序倒序控制，如：displayOrder ASC,Speed DESC
            if (sbOrder != null)
            {
                if (!string.IsNullOrEmpty(selection.orderFields))
                {
                    //自定义排序
                    string[] arrFields = selection.orderFields.Split(',');
                    foreach (var s in arrFields)
                    {
                        string[] arrField = selection.orderFields.Split(' ');
                        if (tb.Fields.FirstOrDefault(f => f.fieldCode.Equals(arrField[0], StringComparison.OrdinalIgnoreCase)) == null) continue;
                        else { sbOrder.Append(alias); sbOrder.Append("."); sbOrder.Append(s); sbOrder.Append(","); }
                    }
                }
                else if (!string.IsNullOrEmpty(tb.orderField))
                {
                    //该表拥有自己的排序字段
                    sbOrder.Append(alias); sbOrder.Append("."); sbOrder.Append(tb.orderField); sbOrder.Append(",");
                }
            }
            #endregion
            #region 获取查询条件内容SQL预计及参数设置，<字段名>=<值>
            if (selection.conditions != null && selection.conditions.Length > 0)
            {
                int level = 0;
                foreach (var c in selection.conditions)
                {
                    string s = "";
                    VonDefinationField field = tb.Fields.FirstOrDefault(f => f.fieldCode.Equals(c.FieldName, StringComparison.OrdinalIgnoreCase));
                    if (field == null) continue;
                    switch (c.Condition)
                    {
                        case EDBCondition.不等于: s = alias + "." + c.FieldName + "<>@" + addParam(cmd, ref paramIdx, field, c.Data); break;
                        case EDBCondition.等于: s = alias + "." + c.FieldName + "=@" + addParam(cmd, ref paramIdx, field, c.Data); break;
                        case EDBCondition.大于: s = alias + "." + c.FieldName + ">@" + addParam(cmd, ref paramIdx, field, c.Data); break;
                        case EDBCondition.大于等于: s = alias + "." + c.FieldName + ">=@" + addParam(cmd, ref paramIdx, field, c.Data); break;
                        case EDBCondition.小于: s = alias + "." + c.FieldName + "<@" + addParam(cmd, ref paramIdx, field, c.Data); break;
                        case EDBCondition.小于等于: s = alias + "." + c.FieldName + "<=@" + addParam(cmd, ref paramIdx, field, c.Data); break;
                        case EDBCondition.前近似: s = alias + "." + c.FieldName + " LIKE '%' + @" + addParam(cmd, ref paramIdx, field, c.Data); break;
                        case EDBCondition.后近似: s = alias + "." + c.FieldName + " LIKE @" + addParam(cmd, ref paramIdx, field, c.Data) + " + '%'"; break;
                        case EDBCondition.前后近似: s = alias + "." + c.FieldName + " LIKE '%' + @" + addParam(cmd, ref paramIdx, field, c.Data) + " + '%'"; break;
                        case EDBCondition.在其中:
                            string[] datas = c.Data.ToString().Split(',');
                            s = alias + "." + c.FieldName + " in (";
                            foreach (var ds in datas)
                            {
                                s += "@" + addParam(cmd, ref paramIdx, field, ds) + ",";
                            }
                            s = s.Trim(',') + ")";
                            break;
                        case EDBCondition.范围:
                            string[] bs = c.Data.ToString().Split(',');
                            s = alias + "." + c.FieldName + " between @" + addParam(cmd, ref paramIdx, field, bs[0]) + " AND @" + addParam(cmd, ref paramIdx, field, bs[1]);
                            break;
                    }
                    if (sbWhere.Length == 0) { sbWhere.Append(getBrackets(c.Level - level)); sbWhere.Append(s); }
                    else switch (c.Connector)
                        {
                            case DBConditionConnector.NONE: sbWhere.Append(getBrackets(c.Level - level)); sbWhere.Append(s); break;
                            case DBConditionConnector.AND: sbWhere.Append(" AND "); sbWhere.Append(getBrackets(c.Level - level)); sbWhere.Append(s); break;
                            case DBConditionConnector.OR: sbWhere.Append(" OR "); sbWhere.Append(getBrackets(c.Level - level)); sbWhere.Append(s); break;
                        }
                    level = c.Level;
                }
                sbWhere.Append(getBrackets(-level));
            }
            #endregion
            alias++;
            if (selection.Joins != null && selection.Joins.Length > 0)
            {
                foreach (var j in selection.Joins)
                {
                    analyzeSelection(cmd, ref alias, ref paramIdx, j, tbls, sbSelect, sbWhere, sbOrder);
                }
            }
        }
        /// <summary>
        /// 读取一条数据
        /// </summary>
        /// <param name="reader">数据访问查询接口</param>
        /// <param name="data"></param>
        private void readData(IDataReader reader, Dictionary<string, object> data)
        {
            for (int i = 0; i < reader.FieldCount; i++)
            {
                data.Add(reader.GetName(i), reader.GetValue(i));
            }
        }
        #endregion
        /// <summary>
        /// 创建数据库连接
        /// </summary>
        public override SqlConnection CreateConnection()
        {
            SqlConnection conn = new SqlConnection(AppDefination.DBConnectString);
            conn.Open();
            return conn;
        }
        /// <summary>
        /// 开启一个数据库事务
        /// </summary>
        public override SqlTransaction BeginDBTrans()
        {
            return CreateConnection().BeginTransaction();
        }
        /// <summary>
        /// 创建SQL语句执行单元
        /// </summary>
        public override SqlCommand InitCommand(string sqlText, DbTransaction DBTrans)
        {
            if (DBTrans == null) return new SqlCommand(sqlText, CreateConnection());
            return new SqlCommand(sqlText, (SqlConnection)DBTrans.Connection, (SqlTransaction)DBTrans);
        }
        /// <summary>
        /// 树形结构移动位置
        /// </summary>
        /// <param name="tableCode">表名称</param>
        /// <param name="key">主键值</param>
        /// <param name="newPID">新位置的父节点值</param
        /// <param name="newOrder">新的排序位置值</param>
        /// <returns></returns>
        public override bool TreeMove<T>(string tableCode, T key, T newPID, int newOrder, DbTransaction trans = null)
        {
            SqlCommand cmd = Statement.InitCommand("EXEC " + AppDefination.Owner + AppDefination.Qualifier + "Move_" + tableCode + " @ID, @PID, @Ord", trans);
            cmd.Parameters.AddWithValue("@ID", key);
            cmd.Parameters.AddWithValue("@PID", newPID);
            cmd.Parameters.AddWithValue("@Ord", newOrder);
            int result = cmd.ExecuteNonQuery();
            if (trans == null)
                cmd.Connection.Close();
            return result > 0;
        }
        /// <summary>
        /// 读取数据库表中内容
        /// </summary>
        /// <param name="SQL">查询的SQL语句</param>
        /// <param name="Param">键值对的参数设置</param>
        /// <returns></returns>
        public override Dictionary<string, object> GetFromDB(string SQL, Dictionary<string, object> Param = null)
        {
            SqlCommand cmd = InitCommand(SQL, null);
            if (Param != null)
                foreach (var v in Param)
                    cmd.Parameters.Add(new SqlParameter(v.Key, v.Value));
            IDataReader reader = cmd.ExecuteReader();
            //获取查询结果
            Dictionary<string, object> result = new Dictionary<string, object>();
            if (reader.Read()) readData(reader, result);
            reader.Close();
            cmd.Connection.Close();
            return result;
        }
        /// <summary>
        /// 读取数据库表中内容
        /// </summary>
        /// <param name="SQL">查询的SQL语句</param>
        /// <param name="Param">键值对的参数设置</param>
        /// <returns></returns>
        public override Dictionary<string, object> GetFromDB(string SQL, JObject Param = null)
        {
            SqlCommand cmd = InitCommand(SQL, null);
            if (Param != null)
                foreach (var v in Param)
                    cmd.Parameters.Add(new SqlParameter(v.Key, v.Value));
            IDataReader reader = cmd.ExecuteReader();
            //获取查询结果
            Dictionary<string, object> result = new Dictionary<string, object>();
            if (reader.Read()) readData(reader, result);
            reader.Close();
            cmd.Connection.Close();
            return result;
        }
        /// <summary>
        /// 读取数据库表中内容
        /// </summary>
        /// <param name="selection">要选择的内容，selection={TableCode:TableCode,Fields:[Field...],Joins:[selection...]}</param>
        /// <param name="conditions">要选择的条件设置，conditions=[condition...]，condition={Connector:NONE|AND|OR,Level=Level,FieldName=FieldName,Condition=Condition,Data=Data}</param>
        /// <returns></returns>
        public override Dictionary<string, object> GetFromDB(JObject selection)
        {
            List<DBTableCondition> tbls = new List<DBTableCondition>();
            StringBuilder sbSelect = new StringBuilder();
            StringBuilder sbFrom = new StringBuilder();
            StringBuilder sbWhere = new StringBuilder();
            StringBuilder sbOrder = new StringBuilder();
            SqlCommand cmd = InitCommand("", null);
            char alias = 'A'; int paramIdx = 1;
            analyzeSelection(cmd, ref alias, ref paramIdx, selection, tbls, sbSelect, sbWhere, sbOrder);
            tablesToJoin(tbls, sbFrom);                     //根据所有Tables生成From语句
            cmd.CommandText = "SELECT TOP 1 " + sbSelect.ToString().TrimEnd(',') + sbFrom.ToString() + (sbWhere.Length > 0 ? " WHERE " + sbWhere.ToString() : "");
            Von.Web.Framework.Runtime.Log.Debug("ListFromDB" + cmd.CommandText);
            IDataReader reader = cmd.ExecuteReader();
            //获取查询结果
            Dictionary<string, object> result = new Dictionary<string, object>();
            if (reader.Read()) readData(reader, result);
            reader.Close();
            cmd.Connection.Close();
            return result;
        }
        /// <summary>
        /// 读取数据库表中内容
        /// </summary>
        /// <param name="selection">要选择的内容</param>
        /// <param name="conditions">要选择的条件设置</param>
        /// <returns></returns>
        public override Dictionary<string, object> GetFromDB(DBSelection selection)
        {
            List<DBTableCondition> tbls = new List<DBTableCondition>();
            StringBuilder sbSelect = new StringBuilder();
            StringBuilder sbFrom = new StringBuilder();
            StringBuilder sbWhere = new StringBuilder();
            SqlCommand cmd = InitCommand("", null);
            char alias = 'A'; int paramIdx = 1;
            analyzeSelection(cmd, ref alias, ref paramIdx, selection, tbls, sbSelect, sbWhere, null);
            tablesToJoin(tbls, sbFrom);                     //根据所有Tables生成From语句
            cmd.CommandText = "SELECT TOP 1 " + sbSelect.ToString().TrimEnd(',') + sbFrom.ToString() + (sbWhere.Length > 0 ? " WHERE " + sbWhere.ToString() : "");
            IDataReader reader = cmd.ExecuteReader();
            //获取查询结果
            Dictionary<string, object> result = new Dictionary<string, object>();
            if (reader.Read()) readData(reader, result);
            reader.Close();
            cmd.Connection.Close();
            return result;
        }
        /// <summary>
        /// 读取数据库表中内容
        /// </summary>
        /// <param name="SQL">查询的SQL语句</param>
        /// <param name="Param">键值对的参数设置</param>
        /// <returns></returns>
        public override List<Dictionary<string, object>> ListFromDB(string SQL, Dictionary<string, object> Param = null)
        {
            Von.Web.Framework.Runtime.Log.DebugFormat("Will to list from db with {0}, {1}", SQL, Param);
            SqlCommand cmd = InitCommand(SQL, null);
            if (Param != null)
                foreach (var v in Param)
                    cmd.Parameters.Add(new SqlParameter(v.Key, v.Value));
            IDataReader reader = cmd.ExecuteReader();
            //获取查询结果
            List<Dictionary<string, object>> result = new List<Dictionary<string, object>>();
            while (reader.Read())
            {
                Dictionary<string, object> data = new Dictionary<string, object>();
                readData(reader, data);
                result.Add(data);
            }
            reader.Close();
            cmd.Connection.Close();
            return result;
        }
        /// <summary>
        /// 读取数据库表中内容
        /// </summary>
        /// <param name="SQL">查询的SQL语句</param>
        /// <param name="Param">键值对的参数设置</param>
        /// <returns></returns>
        public override List<Dictionary<string, object>> ListFromDB(string SQL, JObject Param = null)
        {
            SqlCommand cmd = InitCommand(SQL, null);
            if (Param != null)
                foreach (var v in Param)
                    cmd.Parameters.Add(new SqlParameter(v.Key, v.Value));
            IDataReader reader = cmd.ExecuteReader();
            //获取查询结果
            List<Dictionary<string, object>> result = new List<Dictionary<string, object>>();
            while (reader.Read())
            {
                Dictionary<string, object> data = new Dictionary<string, object>();
                readData(reader, data);
                result.Add(data);
            }
            reader.Close();
            cmd.Connection.Close();
            return result;
        }
        /// <summary>
        /// 读取数据库表中内容
        /// </summary>
        /// <param name="selection">要选择的内容，selection={TableCode:TableCode,Fields:[Field...],Joins:[selection...]}</param>
        /// <param name="conditions">要选择的条件设置，conditions=[condition...]，condition={Connector:NONE|AND|OR,Level=Level,FieldName=FieldName,Condition=Condition,Data=Data}</param>
        /// <returns></returns>
        public override List<Dictionary<string, object>> ListFromDB(JObject selection)
        {
            List<DBTableCondition> tbls = new List<DBTableCondition>();
            StringBuilder sbSelect = new StringBuilder();
            StringBuilder sbFrom = new StringBuilder();
            StringBuilder sbWhere = new StringBuilder();
            StringBuilder sbOrder = new StringBuilder();
            SqlCommand cmd = InitCommand("", null);
            char alias = 'A'; int paramIdx = 1;
            analyzeSelection(cmd, ref alias, ref paramIdx, selection, tbls, sbSelect, sbWhere, sbOrder);
            tablesToJoin(tbls, sbFrom);                     //根据所有Tables生成From语句
            cmd.CommandText = "SELECT " + sbSelect.ToString().TrimEnd(',') + sbFrom.ToString() + (sbWhere.Length > 0 ? " WHERE " + sbWhere.ToString() : "") + (sbOrder.Length > 0 ? " ORDER BY " + sbOrder.ToString().TrimEnd(',') : "");
            Von.Web.Framework.Runtime.Log.Debug("ListFromDB" + cmd.CommandText);
            IDataReader reader = cmd.ExecuteReader();
            //获取查询结果
            List<Dictionary<string, object>> result = new List<Dictionary<string, object>>();
            while (reader.Read())
            {
                Dictionary<string, object> data = new Dictionary<string, object>();
                readData(reader, data);
                result.Add(data);
            }
            reader.Close();
            cmd.Connection.Close();
            return result;
        }
        /// <summary>
        /// 读取数据库表中内容
        /// </summary>
        /// <param name="selection">要选择的内容</param>
        /// <param name="conditions">要选择的条件设置</param>
        /// <returns></returns>
        public override List<Dictionary<string, object>> ListFromDB(DBSelection selection)
        {
            List<DBTableCondition> tbls = new List<DBTableCondition>();
            StringBuilder sbSelect = new StringBuilder();
            StringBuilder sbFrom = new StringBuilder();
            StringBuilder sbWhere = new StringBuilder();
            StringBuilder sbOrder = new StringBuilder();
            SqlCommand cmd = InitCommand("", null);
            char alias = 'A'; int paramIdx = 1;
            analyzeSelection(cmd, ref alias, ref paramIdx, selection, tbls, sbSelect, sbWhere, sbOrder);
            tablesToJoin(tbls, sbFrom);                     //根据所有Tables生成From语句
            cmd.CommandText = "SELECT " + sbSelect.ToString().TrimEnd(',') + sbFrom.ToString() + (sbWhere.Length > 0 ? " WHERE " + sbWhere.ToString() : "") + (sbOrder.Length > 0 ? " ORDER BY " + sbOrder.ToString().TrimEnd(',') : "");
            Von.Web.Framework.Runtime.Log.Debug("ListFromDB" + cmd.CommandText);
            IDataReader reader = cmd.ExecuteReader();
            //获取查询结果
            List<Dictionary<string, object>> result = new List<Dictionary<string, object>>();
            while (reader.Read())
            {
                Dictionary<string, object> data = new Dictionary<string, object>();
                readData(reader, data);
                result.Add(data);
            }
            reader.Close();
            cmd.Connection.Close();
            return result;
        }
        /// <summary>
        /// 插入表数据
        /// </summary>
        /// <param name="tableCode">表名称</param>
        /// <param name="values">字段内容列表</param>
        /// <param name="trans">事务</param>
        /// <returns>是否成功</returns>
        public override bool InsertToDB(string tableCode, Dictionary<string, object> values, DbTransaction trans = null)
        {
            VonTableDefination tbl = tables.FirstOrDefault(t => t.tableCode.Equals(tableCode, StringComparison.OrdinalIgnoreCase));
            SqlCommand cmd = InitCommand("", trans);
            StringBuilder sql_fields = new StringBuilder();
            StringBuilder sql_values = new StringBuilder();
            foreach (var v in values)
            {
                VonDefinationField field = tbl.Fields.FirstOrDefault(f => f.fieldCode.Equals(v.Key, StringComparison.OrdinalIgnoreCase));
                if (field == null) continue;
                sql_fields.Append(",[" + v.Key + "]");
                sql_values.Append(",@" + v.Key);
                newSqlParameter(cmd, v.Key, (SqlDbType)field.fieldType, v.Value);
            }
            sql_fields.Remove(0, 1);
            sql_values.Remove(0, 1);
            cmd.CommandText = "INSERT INTO " + AppDefination.Owner + AppDefination.Qualifier + tableCode + "(" + sql_fields.ToString() +
                ")VALUES(" + sql_values.ToString() + ")";
            int result = cmd.ExecuteNonQuery();
            if (trans == null)
                cmd.Connection.Close();
            return result > 0;
        }
        /// <summary>
        /// 插入表数据
        /// </summary>
        /// <param name="tableCode">表名称</param>
        /// <param name="values">字段内容列表</param>
        /// <param name="trans">事务</param>
        /// <returns>是否成功</returns>
        public override bool InsertToDB(string tableCode, JObject values, DbTransaction trans = null)
        {
            VonTableDefination tbl = tables.FirstOrDefault(t => t.tableCode.Equals(tableCode, StringComparison.OrdinalIgnoreCase));
            SqlCommand cmd = InitCommand("", trans);
            StringBuilder sql_fields = new StringBuilder();
            StringBuilder sql_values = new StringBuilder();
            foreach (var v in values)
            {
                VonDefinationField field = tbl.Fields.FirstOrDefault(f => f.fieldCode.Equals(v.Key, StringComparison.OrdinalIgnoreCase));
                if (field == null) continue;
                sql_fields.Append(",[" + v.Key + "]");
                sql_values.Append(",@" + v.Key);
                newSqlParameter(cmd, v.Key, (SqlDbType)field.fieldType, v.Value);
            }
            sql_fields.Remove(0, 1);
            sql_values.Remove(0, 1);
            cmd.CommandText = "INSERT INTO " + AppDefination.Owner + AppDefination.Qualifier + tableCode + "(" + sql_fields.ToString() +
                ")VALUES(" + sql_values.ToString() + ")";
            int result = cmd.ExecuteNonQuery();
            if (trans == null)
                cmd.Connection.Close();
            return result > 0;
        }
        /// <summary>
        /// 插入后，返回键值
        /// </summary>
        /// <param name="tableCode">表名称</param>
        /// <param name="values">字段内容列表</param>
        /// <param name="trans">事务</param>
        /// <returns>返回插入的主键</returns>
        public override object InsertIdentity(string tableCode, Dictionary<string, object> values, DbTransaction trans = null)
        {
            VonTableDefination tbl = tables.FirstOrDefault(t => t.tableCode.Equals(tableCode, StringComparison.OrdinalIgnoreCase));
            SqlCommand cmd = InitCommand("", trans);
            StringBuilder sql_fields = new StringBuilder();
            StringBuilder sql_values = new StringBuilder();
            foreach (var v in values)
            {
                if (v.Key.Equals(tbl.keyField, StringComparison.OrdinalIgnoreCase)) continue;
                VonDefinationField field = tbl.Fields.FirstOrDefault(f => f.fieldCode.Equals(v.Key, StringComparison.OrdinalIgnoreCase));
                if (field == null) continue;
                sql_fields.Append(",[" + v.Key + "]");
                sql_values.Append(",@" + v.Key);
                newSqlParameter(cmd, v.Key, (SqlDbType)field.fieldType, v.Value);
            }
            sql_fields.Remove(0, 1);
            sql_values.Remove(0, 1);
            cmd.CommandText = "INSERT INTO " + AppDefination.Owner + AppDefination.Qualifier + tableCode + "(" + sql_fields.ToString() +
                ")OUTPUT INSERTED." + tbl.keyField + " VALUES(" + sql_values.ToString() + ")";
            object result = cmd.ExecuteScalar();
            if (trans == null)
                cmd.Connection.Close();
            return result;
        }
        /// <summary>
        /// 插入后，返回键值
        /// </summary>
        /// <param name="tableCode">表名称</param>
        /// <param name="values">字段内容列表</param>
        /// <param name="trans">事务</param>
        /// <returns>返回插入的主键</returns>
        public override object InsertIdentity(string tableCode, JObject values, DbTransaction trans = null)
        {
            VonTableDefination tbl = tables.FirstOrDefault(t => t.tableCode.Equals(tableCode, StringComparison.OrdinalIgnoreCase));
            SqlCommand cmd = InitCommand("", trans);
            StringBuilder sql_fields = new StringBuilder();
            StringBuilder sql_values = new StringBuilder();
            foreach (var v in values)
            {
                if (v.Key.Equals(tbl.keyField, StringComparison.OrdinalIgnoreCase)) continue;
                VonDefinationField field = tbl.Fields.FirstOrDefault(f => f.fieldCode.Equals(v.Key, StringComparison.OrdinalIgnoreCase));
                if (field == null) continue;
                sql_fields.Append(",[" + v.Key + "]");
                sql_values.Append(",@" + v.Key);
                newSqlParameter(cmd, v.Key, (SqlDbType)field.fieldType, v.Value);
            }
            sql_fields.Remove(0, 1);
            sql_values.Remove(0, 1);
            cmd.CommandText = "INSERT INTO " + AppDefination.Owner + AppDefination.Qualifier + tableCode + "(" + sql_fields.ToString() +
                ")OUTPUT INSERTED." + tbl.keyField + " VALUES(" + sql_values.ToString() + ")";
            object result = cmd.ExecuteScalar();
            if (trans == null)
                cmd.Connection.Close();
            return result;
        }
        /// <summary>
        /// 更新数据表字段内容
        /// </summary>
        /// <param name="tableCode">表名称</param>
        /// <param name="values">字段内容列表</param>
        /// <param name="trans">事务</param>
        /// <returns>是否成功</returns>
        public override bool UpdateToDB(string tableCode, Dictionary<string, object> values, DbTransaction trans = null)
        {
            VonTableDefination tbl = tables.FirstOrDefault(t => t.tableCode.Equals(tableCode, StringComparison.OrdinalIgnoreCase));
            SqlCommand cmd = InitCommand("", trans);
            StringBuilder sql_fields = new StringBuilder();
            foreach (var v in values)
            {
                VonDefinationField field = tbl.Fields.FirstOrDefault(f => f.fieldCode.Equals(v.Key, StringComparison.OrdinalIgnoreCase));
                if (field == null) continue;
                if (!v.Key.Equals(tbl.keyField, StringComparison.OrdinalIgnoreCase))
                    sql_fields.Append(",[" + v.Key + "]=@" + v.Key);
                newSqlParameter(cmd, v.Key, (SqlDbType)field.fieldType, v.Value);
            }
            sql_fields.Remove(0, 1);
            cmd.CommandText = "UPDATE " + AppDefination.Owner + AppDefination.Qualifier + tableCode + " SET " + sql_fields.ToString() +
                " WHERE " + tbl.keyField + "=@" + tbl.keyField;
            int result = cmd.ExecuteNonQuery();
            if (trans == null)
                cmd.Connection.Close();
            return result > 0;
        }
        /// <summary>
        /// 更新数据表字段内容
        /// </summary>
        /// <param name="tableCode">表名称</param>
        /// <param name="values">字段内容列表</param>
        /// <param name="trans">事务</param>
        /// <returns>是否成功</returns>
        public override bool UpdateToDB(string tableCode, JObject values, DbTransaction trans = null)
        {
            VonTableDefination tbl = tables.FirstOrDefault(t => t.tableCode.Equals(tableCode, StringComparison.OrdinalIgnoreCase));
            SqlCommand cmd = InitCommand("", trans);
            StringBuilder sql_fields = new StringBuilder();
            foreach (var v in values)
            {
                if (tbl.Fields.FirstOrDefault(f => f.fieldCode.Equals(v.Key, StringComparison.OrdinalIgnoreCase)) == null) continue;
                if (!v.Key.Equals(tbl.keyField, StringComparison.OrdinalIgnoreCase))
                    sql_fields.Append(",[" + v.Key + "]=@" + v.Key);
                SqlParameter p = new SqlParameter("@" + v.Key, v.Value.ToString());
                cmd.Parameters.Add(p);
            }
            sql_fields.Remove(0, 1);
            cmd.CommandText = "UPDATE " + AppDefination.Owner + AppDefination.Qualifier + tableCode + " SET " + sql_fields.ToString() +
                " WHERE " + tbl.keyField + "=@" + tbl.keyField;
            int result = cmd.ExecuteNonQuery();
            if (trans == null)
                cmd.Connection.Close();
            return result > 0;
        }
        /// <summary>
        /// 删除数据表内容
        /// </summary>
        /// <param name="tableCode">表名称</param>
        /// <param name="value">主键值</param>
        /// <param name="trans">事务</param>
        /// <returns>是否成功</returns>
        public override bool DeleteFromDB(string tableCode, object keyValue, DbTransaction trans = null)
        {
            VonTableDefination tbl = tables.FirstOrDefault(t => t.tableCode.Equals(tableCode, StringComparison.OrdinalIgnoreCase));
            SqlCommand cmd = InitCommand("DELETE " + AppDefination.Owner + AppDefination.Qualifier + tableCode + " WHERE " + tbl.keyField + "=@" + tbl.keyField, trans);
            cmd.Parameters.Add(new SqlParameter("@" + tbl.keyField, keyValue));
            int result = cmd.ExecuteNonQuery();
            if (trans == null)
                cmd.Connection.Close();
            return result > 0;
        }
        /// <summary>
        /// 根据条件删除数据表内容
        /// </summary>
        /// <param name="tableCode">表名称</param>
        /// <param name="values">删除条件集合</param>
        /// <param name="trans">事务</param>
        /// <returns>是否成功</returns>
        public override bool DeleteByCondition(string tableCode, Dictionary<string, object> values, DbTransaction trans = null)
        {
            VonTableDefination tbl = tables.FirstOrDefault(t => t.tableCode.Equals(tableCode, StringComparison.OrdinalIgnoreCase));
            SqlCommand cmd = InitCommand("", trans);
            StringBuilder sql_condition = new StringBuilder();
            foreach (var v in values)
            {
                if (tbl.Fields.FirstOrDefault(f => f.fieldCode.Equals(v.Key, StringComparison.OrdinalIgnoreCase)) == null) continue;
                if (sql_condition.Length > 0) sql_condition.Append(" AND ");
                sql_condition.Append("[" + v.Key + "]=@" + v.Key);
                SqlParameter p = new SqlParameter("@" + v.Key, v.Value);
                cmd.Parameters.Add(p);
            }
            cmd.CommandText = "DELETE FROM " + AppDefination.Owner + AppDefination.Qualifier + tableCode + " WHERE " + sql_condition.ToString();
            int result = cmd.ExecuteNonQuery();
            if (trans == null)
                cmd.Connection.Close();
            return result > 0;
        }
        /// <summary>
        /// 根据条件删除数据表内容
        /// </summary>
        /// <param name="tableCode">表名称</param>
        /// <param name="values">删除条件集合</param>
        /// <param name="trans">事务</param>
        /// <returns>是否成功</returns>
        public override bool DeleteByCondition(string tableCode, JObject values, DbTransaction trans = null)
        {
            VonTableDefination tbl = tables.FirstOrDefault(t => t.tableCode.Equals(tableCode, StringComparison.OrdinalIgnoreCase));
            SqlCommand cmd = InitCommand("", trans);
            StringBuilder sql_condition = new StringBuilder();
            foreach (var v in values)
            {
                if (tbl.Fields.FirstOrDefault(f => f.fieldCode.Equals(v.Key, StringComparison.OrdinalIgnoreCase)) == null) continue;
                if (sql_condition.Length > 0) sql_condition.Append(" AND ");
                sql_condition.Append("[" + v.Key + "]=@" + v.Key);
                SqlParameter p = new SqlParameter("@" + v.Key, v.Value.ToString());
                cmd.Parameters.Add(p);
            }
            cmd.CommandText = "DELETE FROM " + AppDefination.Owner + AppDefination.Qualifier + tableCode + " WHERE " + sql_condition.ToString();
            int result = cmd.ExecuteNonQuery();
            if (trans == null)
                cmd.Connection.Close();
            return result > 0;
        }
        private Dictionary<string, int> _DBTypes = null;
        public override Dictionary<string, int> DBTypes
        {
            get
            {
                if (_DBTypes == null)
                {
                    _DBTypes = new Dictionary<string, int>();
                    foreach (SqlDbType t in Enum.GetValues(typeof(SqlDbType)))
                    {
                        _DBTypes.Add(t.ToString(), (int)t);
                    }
                }
                return _DBTypes;
            }
        }
        private void newSqlParameter(SqlCommand cmd, string key, SqlDbType type, object value)
        {
            cmd.Parameters.Add(key, type).Value = value;
            //if (type.Substring(0, 3).Equals("Bit", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.Bit).Value = value;
            //else if (type.Substring(0, 3).Equals("Int", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.Int).Value = value;
            //else if (type.Substring(0, 3).Equals("Xml", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.Xml).Value = value.ToString();
            //else if (type.Substring(0, 3).Equals("Udt", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.Udt).Value = value;
            //else if (type.Substring(0, 4).Equals("Char", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.Char).Value = value.ToString();
            //else if (type.Substring(0, 4).Equals("Real", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.Real).Value = value;
            //else if (type.Substring(0, 4).Equals("Text", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.Text).Value = value.ToString();
            //else if (type.Substring(0, 4).Equals("Date", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.Date).Value = value;
            //else if (type.Substring(0, 4).Equals("Time", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.Time).Value = value;
            //else if (type.Substring(0, 5).Equals("Float", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.Float).Value = value;
            //else if (type.Substring(0, 5).Equals("Image", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.Image).Value = value;
            //else if (type.Substring(0, 5).Equals("Money", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.Money).Value = value;
            //else if (type.Substring(0, 5).Equals("NChar", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.NChar).Value = value.ToString();
            //else if (type.Substring(0, 5).Equals("NText", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.NText).Value = value.ToString();
            //else if (type.Substring(0, 6).Equals("BigInt", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.BigInt).Value = value;
            //else if (type.Substring(0, 6).Equals("Binary", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.Binary).Value = value;
            //else if (type.Substring(0, 7).Equals("Decimal", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.Decimal).Value = value;
            //else if (type.Substring(0, 7).Equals("TinyInt", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.TinyInt).Value = value;
            //else if (type.Substring(0, 7).Equals("VarChar", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.VarChar).Value = value.ToString();
            //else if (type.Substring(0, 7).Equals("Variant", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.Variant).Value = value;
            //else if (type.Substring(0, 8).Equals("DateTime", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.DateTime).Value = value;
            //else if (type.Substring(0, 8).Equals("NVarChar", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.NVarChar).Value = value.ToString();
            //else if (type.Substring(0, 8).Equals("SmallInt", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.SmallInt).Value = value;
            //else if (type.Substring(0, 9).Equals("Timestamp", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.Timestamp).Value = value;
            //else if (type.Substring(0, 9).Equals("VarBinary", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.VarBinary).Value = value;
            //else if (type.Substring(0, 9).Equals("DateTime2", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.DateTime2).Value = value;
            //else if (type.Substring(0, 10).Equals("SmallMoney", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.SmallMoney).Value = value;
            //else if (type.Substring(0, 10).Equals("Structured", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.Structured).Value = value;
            //else if (type.Substring(0, 13).Equals("SmallDateTime", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.SmallDateTime).Value = value;
            //else if (type.Substring(0, 14).Equals("DateTimeOffset", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.DateTimeOffset).Value = value;
            //else if (type.Substring(0, 16).Equals("UniqueIdentifier", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.UniqueIdentifier).Value = value;
            //if (type.Substring(0, 3).Equals("Bit", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.Bit).Value = (bool)value;
            //else if (type.Substring(0, 3).Equals("Int", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.Int).Value = (int)value;
            //else if (type.Substring(0, 3).Equals("Xml", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.Xml).Value = value.ToString();
            //else if (type.Substring(0, 3).Equals("Udt", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.Udt).Value = value;
            //else if (type.Substring(0, 4).Equals("Char", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.Char).Value = value.ToString();
            //else if (type.Substring(0, 4).Equals("Real", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.Real).Value = (Single)value;
            //else if (type.Substring(0, 4).Equals("Text", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.Text).Value = value.ToString();
            //else if (type.Substring(0, 4).Equals("Date", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.Date).Value = (DateTime)value;
            //else if (type.Substring(0, 4).Equals("Time", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.Time).Value = (TimeSpan)value;
            //else if (type.Substring(0, 5).Equals("Float", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.Float).Value = (double)value;
            //else if (type.Substring(0, 5).Equals("Image", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.Image).Value = (byte[])value;
            //else if (type.Substring(0, 5).Equals("Money", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.Money).Value = (decimal)value;
            //else if (type.Substring(0, 5).Equals("NChar", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.NChar).Value = value.ToString();
            //else if (type.Substring(0, 5).Equals("NText", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.NText).Value = value.ToString();
            //else if (type.Substring(0, 6).Equals("BigInt", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.BigInt).Value = (long)value;
            //else if (type.Substring(0, 6).Equals("Binary", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.Binary).Value = (byte[])value;
            //else if (type.Substring(0, 7).Equals("Decimal", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.Decimal).Value = (decimal)value;
            //else if (type.Substring(0, 7).Equals("TinyInt", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.TinyInt).Value = (int)value;
            //else if (type.Substring(0, 7).Equals("VarChar", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.VarChar).Value = value.ToString();
            //else if (type.Substring(0, 7).Equals("Variant", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.Variant).Value = (byte[])value;
            //else if (type.Substring(0, 8).Equals("DateTime", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.DateTime).Value = (DateTime)value;
            //else if (type.Substring(0, 8).Equals("NVarChar", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.NVarChar).Value = value.ToString();
            //else if (type.Substring(0, 8).Equals("SmallInt", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.SmallInt).Value = (short)value;
            //else if (type.Substring(0, 9).Equals("Timestamp", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.Timestamp).Value = (byte[])value;
            //else if (type.Substring(0, 9).Equals("VarBinary", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.VarBinary).Value = (byte[])value;
            //else if (type.Substring(0, 9).Equals("DateTime2", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.DateTime2).Value = (DateTime)value;
            //else if (type.Substring(0, 10).Equals("SmallMoney", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.SmallMoney).Value = (decimal)value;
            //else if (type.Substring(0, 10).Equals("Structured", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.Structured).Value = (byte[])value;
            //else if (type.Substring(0, 13).Equals("SmallDateTime", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.SmallDateTime).Value = (DateTime)value;
            //else if (type.Substring(0, 14).Equals("DateTimeOffset", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.DateTimeOffset).Value = (DateTimeOffset)value;
            //else if (type.Substring(0, 16).Equals("UniqueIdentifier", StringComparison.OrdinalIgnoreCase)) cmd.Parameters.Add(key, SqlDbType.UniqueIdentifier).Value = value;
        }
    }
    public class SqlAccession : SqlApplicationDBAccessionBase
    {
        #region Table defination
        /// <summary>
        /// 本应用中的数据库表结构
        /// </summary>
        public override VonTableDefination[] tables
        {
            get => new VonTableDefination[]{
                new VonTableDefination(){
                    tableCode = "Right",
                    tableName = "权限控制",
                    keyField = "ID",
                    parentField = "",
                    orderField = "",
                    Fields=new VonDefinationField[]{
                    new VonDefinationField() {fieldCode = "ID", fieldName = "序号", fieldType = (int)SqlDbType.Int },
                    new VonDefinationField() {fieldCode = "RoleName", fieldName = "角色名称", fieldType = (int)SqlDbType.NVarChar },
                    new VonDefinationField() {fieldCode = "DestIdx", fieldName = "控制目标序号", fieldType = (int)SqlDbType.UniqueIdentifier },
                    new VonDefinationField() {fieldCode = "Kind", fieldName = "控制类型", fieldType = (int)SqlDbType.Int },
                    },
                    Reference = new VonTableReference[]{
                    new VonTableReference() {srcField = "RoleName", destTable = "Role", destField = "RoleName" },
                    }
                },
                new VonTableDefination(){
                    tableCode = "Menu",
                    tableName = "站点菜单",
                    keyField = "ID",
                    parentField = "PID",
                    orderField = "DisplayOrder",
                    Fields=new VonDefinationField[]{
                    new VonDefinationField() {fieldCode = "ID", fieldName = "序号", fieldType = (int)SqlDbType.UniqueIdentifier },
                    new VonDefinationField() {fieldCode = "MenuName", fieldName = "菜单名称", fieldType = (int)SqlDbType.NVarChar },
                    new VonDefinationField() {fieldCode = "PID", fieldName = "父节点", fieldType = (int)SqlDbType.UniqueIdentifier },
                    new VonDefinationField() {fieldCode = "MenuClass", fieldName = "菜单样式", fieldType = (int)SqlDbType.NVarChar },
                    new VonDefinationField() {fieldCode = "iconFilename", fieldName = "菜单图标", fieldType = (int)SqlDbType.NVarChar },
                    new VonDefinationField() {fieldCode = "MenuData", fieldName = "菜单内容", fieldType = (int)SqlDbType.NVarChar },
                    new VonDefinationField() {fieldCode = "DisplayOrder", fieldName = "显示顺序", fieldType = (int)SqlDbType.Int },
                    },
                    Reference = new VonTableReference[]{
                    }
                },
                new VonTableDefination(){
                    tableCode = "User",
                    tableName = "系统登录人员信息",
                    keyField = "ID",
                    parentField = "",
                    orderField = "",
                    Fields=new VonDefinationField[]{
                    new VonDefinationField() {fieldCode = "ID", fieldName = "序号", fieldType = (int)SqlDbType.UniqueIdentifier },
                    new VonDefinationField() {fieldCode = "LoginName", fieldName = "登录名", fieldType = (int)SqlDbType.NVarChar },
                    new VonDefinationField() {fieldCode = "Email", fieldName = "Email", fieldType = (int)SqlDbType.NVarChar },
                    new VonDefinationField() {fieldCode = "EmailConfirmed", fieldName = "Email确认状态", fieldType = (int)SqlDbType.Bit },
                    new VonDefinationField() {fieldCode = "PhoneNumber", fieldName = "手机号", fieldType = (int)SqlDbType.VarChar },
                    new VonDefinationField() {fieldCode = "PhoneNumberConfirmed", fieldName = "手机确认状态", fieldType = (int)SqlDbType.Bit },
                    new VonDefinationField() {fieldCode = "PasswordHash", fieldName = "密码", fieldType = (int)SqlDbType.NVarChar },
                    new VonDefinationField() {fieldCode = "SecurityStamp", fieldName = "解锁Token", fieldType = (int)SqlDbType.NVarChar },
                    new VonDefinationField() {fieldCode = "LockoutEnabled", fieldName = "锁定状态", fieldType = (int)SqlDbType.Bit },
                    new VonDefinationField() {fieldCode = "LockoutEnd", fieldName = "自动解锁时间", fieldType = (int)SqlDbType.DateTime },
                    new VonDefinationField() {fieldCode = "DisplayName", fieldName = "显示姓名", fieldType = (int)SqlDbType.NVarChar },
                    new VonDefinationField() {fieldCode = "AccessFailedCount", fieldName = "登录失败次数", fieldType = (int)SqlDbType.Int },
                    new VonDefinationField() {fieldCode = "Status", fieldName = "状态", fieldType = (int)SqlDbType.NVarChar },
                    new VonDefinationField() {fieldCode = "UserIcon", fieldName = "头像", fieldType = (int)SqlDbType.Image },
                    new VonDefinationField() {fieldCode = "SysFlag", fieldName = "系统标识", fieldType = (int)SqlDbType.Int },
                    new VonDefinationField() {fieldCode = "defaultPage", fieldName = "默认页面", fieldType = (int)SqlDbType.NVarChar },
                    },
                    Reference = new VonTableReference[]{
                    }
                },
                new VonTableDefination(){
                    tableCode = "Role",
                    tableName = "系统角色信息",
                    keyField = "RoleName",
                    parentField = "",
                    orderField = "",
                    Fields=new VonDefinationField[]{
                    new VonDefinationField() {fieldCode = "RoleName", fieldName = "角色名称", fieldType = (int)SqlDbType.NVarChar },
                    new VonDefinationField() {fieldCode = "Note", fieldName = "角色描述", fieldType = (int)SqlDbType.NVarChar },
                    new VonDefinationField() {fieldCode = "RoleGroup", fieldName = "角色组名称", fieldType = (int)SqlDbType.NVarChar },
                    },
                    Reference = new VonTableReference[]{
                    }
                },
                new VonTableDefination(){
                    tableCode = "UserRole",
                    tableName = "人员角色关联",
                    keyField = "ID",
                    parentField = "",
                    orderField = "",
                    Fields=new VonDefinationField[]{
                    new VonDefinationField() {fieldCode = "ID", fieldName = "序号", fieldType = (int)SqlDbType.Int },
                    new VonDefinationField() {fieldCode = "UserIdx", fieldName = "人员序号", fieldType = (int)SqlDbType.UniqueIdentifier },
                    new VonDefinationField() {fieldCode = "RoleName", fieldName = "角色名称", fieldType = (int)SqlDbType.NVarChar },
                    },
                    Reference = new VonTableReference[]{
                    new VonTableReference() {srcField = "UserIdx", destTable = "User", destField = "ID" },
                    new VonTableReference() {srcField = "RoleName", destTable = "Role", destField = "RoleName" },
                    }
                },
                new VonTableDefination(){
                    tableCode = "Subsidiary",
                    tableName = "人员附属信息",
                    keyField = "ID",
                    parentField = "",
                    orderField = "",
                    Fields=new VonDefinationField[]{
                    new VonDefinationField() {fieldCode = "ID", fieldName = "序号", fieldType = (int)SqlDbType.Int },
                    new VonDefinationField() {fieldCode = "IdentityIdx", fieldName = "人员序号", fieldType = (int)SqlDbType.UniqueIdentifier },
                    new VonDefinationField() {fieldCode = "SubName", fieldName = "项目名称", fieldType = (int)SqlDbType.NVarChar },
                    new VonDefinationField() {fieldCode = "SubValue", fieldName = "项目内容", fieldType = (int)SqlDbType.NVarChar },
                    },
                    Reference = new VonTableReference[]{
                    new VonTableReference() {srcField = "IdentityIdx", destTable = "User", destField = "ID" },
                    }
                },
                new VonTableDefination(){
                    tableCode = "TicketNo",
                    tableName = "票证编码规则",
                    keyField = "RuleName",
                    parentField = "",
                    orderField = "",
                    Fields=new VonDefinationField[]{
                    new VonDefinationField() {fieldCode = "RuleName", fieldName = "规则名称", fieldType = (int)SqlDbType.NVarChar },
                    new VonDefinationField() {fieldCode = "LastTime", fieldName = "最后取值时间", fieldType = (int)SqlDbType.DateTime },
                    new VonDefinationField() {fieldCode = "CurrentID", fieldName = "当前序号", fieldType = (int)SqlDbType.Int },
                    new VonDefinationField() {fieldCode = "Kind", fieldName = "变更类型", fieldType = (int)SqlDbType.Int },
                    new VonDefinationField() {fieldCode = "NumLength", fieldName = "编码长度", fieldType = (int)SqlDbType.Int },
                    new VonDefinationField() {fieldCode = "Rule", fieldName = "编码规则", fieldType = (int)SqlDbType.VarChar },
                    },
                    Reference = new VonTableReference[]{
                    }
                },
                new VonTableDefination(){
                    tableCode = "Option",
                    tableName = "系统选项",
                    keyField = "OptName",
                    parentField = "",
                    orderField = "",
                    Fields=new VonDefinationField[]{
                    new VonDefinationField() {fieldCode = "OptName", fieldName = "参数名称", fieldType = (int)SqlDbType.NVarChar },
                    new VonDefinationField() {fieldCode = "OptKind", fieldName = "参数类型", fieldType = (int)SqlDbType.Int },
                    new VonDefinationField() {fieldCode = "OptInfo", fieldName = "参数说明", fieldType = (int)SqlDbType.NVarChar },
                    new VonDefinationField() {fieldCode = "OptValues", fieldName = "参数值", fieldType = (int)SqlDbType.Text },
                    },
                    Reference = new VonTableReference[]{
                    }
                },
                new VonTableDefination(){
                    tableCode = "Service",
                    tableName = "系统服务",
                    keyField = "ID",
                    parentField = "",
                    orderField = "",
                    Fields=new VonDefinationField[]{
                    new VonDefinationField() {fieldCode = "ID", fieldName = "序号", fieldType = (int)SqlDbType.UniqueIdentifier },
                    new VonDefinationField() {fieldCode = "ServiceName", fieldName = "服务名称", fieldType = (int)SqlDbType.NVarChar },
                    new VonDefinationField() {fieldCode = "InterKind", fieldName = "间隔方式", fieldType = (int)SqlDbType.Int },
                    new VonDefinationField() {fieldCode = "Intervalue", fieldName = "间隔值", fieldType = (int)SqlDbType.Int },
                    new VonDefinationField() {fieldCode = "Necessary", fieldName = "必要性", fieldType = (int)SqlDbType.Bit },
                    new VonDefinationField() {fieldCode = "Status", fieldName = "状态", fieldType = (int)SqlDbType.NVarChar },
                    new VonDefinationField() {fieldCode = "Param", fieldName = "服务参数", fieldType = (int)SqlDbType.NText },
                    },
                    Reference = new VonTableReference[]{
                    }
                },
                new VonTableDefination(){
                    tableCode = "Slider",
                    tableName = "主页广告",
                    keyField = "ID",
                    parentField = "",
                    orderField = "",
                    Fields=new VonDefinationField[]{
                    new VonDefinationField() {fieldCode = "ID", fieldName = "序号", fieldType = (int)SqlDbType.Int },
                    new VonDefinationField() {fieldCode = "Kind", fieldName = "类型", fieldType = (int)SqlDbType.NVarChar },
                    new VonDefinationField() {fieldCode = "Title", fieldName = "名称", fieldType = (int)SqlDbType.NVarChar },
                    new VonDefinationField() {fieldCode = "Import", fieldName = "引用资料", fieldType = (int)SqlDbType.NText },
                    new VonDefinationField() {fieldCode = "Content", fieldName = "内容", fieldType = (int)SqlDbType.NText },
                    new VonDefinationField() {fieldCode = "Validate", fieldName = "有效期", fieldType = (int)SqlDbType.DateTime },
                    new VonDefinationField() {fieldCode = "Linker", fieldName = "链接", fieldType = (int)SqlDbType.NVarChar },
                    },
                    Reference = new VonTableReference[]{
                    }
                },
                new VonTableDefination(){
                    tableCode = "AdministrativeDistrict",
                    tableName = "行政区划",
                    keyField = "Code",
                    parentField = "",
                    orderField = "",
                    Fields=new VonDefinationField[]{
                    new VonDefinationField() {fieldCode = "Code", fieldName = "区划编码", fieldType = (int)SqlDbType.VarChar },
                    new VonDefinationField() {fieldCode = "ADName", fieldName = "名称", fieldType = (int)SqlDbType.NVarChar },
                    new VonDefinationField() {fieldCode = "Level", fieldName = "层级", fieldType = (int)SqlDbType.Int },
                    },
                    Reference = new VonTableReference[]{
                    }
                },
                new VonTableDefination(){
                    tableCode = "HtmlContent",
                    tableName = "文本内容",
                    keyField = "ID",
                    parentField = "",
                    orderField = "",
                    Fields=new VonDefinationField[]{
                    new VonDefinationField() {fieldCode = "ID", fieldName = "序号", fieldType = (int)SqlDbType.Int },
                    new VonDefinationField() {fieldCode = "HtmlName", fieldName = "文档名称", fieldType = (int)SqlDbType.NVarChar },
                    new VonDefinationField() {fieldCode = "Status", fieldName = "状态", fieldType = (int)SqlDbType.NVarChar },
                    new VonDefinationField() {fieldCode = "Title", fieldName = "标题", fieldType = (int)SqlDbType.NVarChar },
                    new VonDefinationField() {fieldCode = "Tags", fieldName = "标签", fieldType = (int)SqlDbType.NVarChar },
                    new VonDefinationField() {fieldCode = "Keyword", fieldName = "关键词", fieldType = (int)SqlDbType.NVarChar },
                    new VonDefinationField() {fieldCode = "Autor", fieldName = "作者", fieldType = (int)SqlDbType.NVarChar },
                    new VonDefinationField() {fieldCode = "Src", fieldName = "来源", fieldType = (int)SqlDbType.NVarChar },
                    new VonDefinationField() {fieldCode = "Linker", fieldName = "链接", fieldType = (int)SqlDbType.NVarChar },
                    new VonDefinationField() {fieldCode = "Publishedate", fieldName = "发布时间", fieldType = (int)SqlDbType.Date },
                    new VonDefinationField() {fieldCode = "CatalogIdx", fieldName = "所属分类", fieldType = (int)SqlDbType.Int },
                    new VonDefinationField() {fieldCode = "Summary", fieldName = "摘要", fieldType = (int)SqlDbType.NText },
                    new VonDefinationField() {fieldCode = "Content", fieldName = "正文", fieldType = (int)SqlDbType.NText },
                    new VonDefinationField() {fieldCode = "BrowserCount", fieldName = "浏览次数", fieldType = (int)SqlDbType.Int },
                    },
                    Reference = new VonTableReference[]{
                    new VonTableReference() {srcField = "CatalogIdx", destTable = "HtmlCatalog", destField = "ID" },
                    }
                },
                new VonTableDefination(){
                    tableCode = "HtmlCatalog",
                    tableName = "文本文档分类",
                    keyField = "ID",
                    parentField = "PID",
                    orderField = "DisplayOrder",
                    Fields=new VonDefinationField[]{
                    new VonDefinationField() {fieldCode = "ID", fieldName = "序号", fieldType = (int)SqlDbType.Int },
                    new VonDefinationField() {fieldCode = "CatalogName", fieldName = "分类名称", fieldType = (int)SqlDbType.NVarChar },
                    new VonDefinationField() {fieldCode = "PID", fieldName = "父级序号", fieldType = (int)SqlDbType.Int },
                    new VonDefinationField() {fieldCode = "Icon", fieldName = "图标", fieldType = (int)SqlDbType.NVarChar },
                    new VonDefinationField() {fieldCode = "DisplayOrder", fieldName = "显示顺序", fieldType = (int)SqlDbType.Int },
                    },
                    Reference = new VonTableReference[]{
                    }
                },
                new VonTableDefination(){
                    tableCode = "Comment",
                    tableName = "评论",
                    keyField = "ID",
                    parentField = "",
                    orderField = "",
                    Fields=new VonDefinationField[]{
                    new VonDefinationField() {fieldCode = "ID", fieldName = "序号", fieldType = (int)SqlDbType.Int },
                    new VonDefinationField() {fieldCode = "Kind", fieldName = "评论文档类型", fieldType = (int)SqlDbType.NVarChar },
                    new VonDefinationField() {fieldCode = "LinkIdx", fieldName = "文档序号", fieldType = (int)SqlDbType.NVarChar },
                    new VonDefinationField() {fieldCode = "Evaluation", fieldName = "点评值", fieldType = (int)SqlDbType.Int },
                    new VonDefinationField() {fieldCode = "Content", fieldName = "评论内容", fieldType = (int)SqlDbType.NText },
                    new VonDefinationField() {fieldCode = "Publishedate", fieldName = "点评日期", fieldType = (int)SqlDbType.DateTime },
                    new VonDefinationField() {fieldCode = "Publisher", fieldName = "点评用户", fieldType = (int)SqlDbType.UniqueIdentifier },
                    new VonDefinationField() {fieldCode = "Email", fieldName = "回复邮箱", fieldType = (int)SqlDbType.NVarChar },
                    new VonDefinationField() {fieldCode = "Concern", fieldName = "关注", fieldType = (int)SqlDbType.Bit },
                    new VonDefinationField() {fieldCode = "Support", fieldName = "支持", fieldType = (int)SqlDbType.Bit },
                    new VonDefinationField() {fieldCode = "Oppose", fieldName = "差评", fieldType = (int)SqlDbType.Bit },
                    new VonDefinationField() {fieldCode = "ReplyContent", fieldName = "回复", fieldType = (int)SqlDbType.NText },
                    new VonDefinationField() {fieldCode = "ReplyDate", fieldName = "回复日期", fieldType = (int)SqlDbType.DateTime },
                    new VonDefinationField() {fieldCode = "Replyer", fieldName = "回复人", fieldType = (int)SqlDbType.UniqueIdentifier },
                    },
                    Reference = new VonTableReference[]{
                    }
                },
                new VonTableDefination(){
                    tableCode = "Image",
                    tableName = "照片资源",
                    keyField = "ID",
                    parentField = "",
                    orderField = "",
                    Fields=new VonDefinationField[]{
                    new VonDefinationField() {fieldCode = "ID", fieldName = "序号", fieldType = (int)SqlDbType.UniqueIdentifier },
                    new VonDefinationField() {fieldCode = "Kind", fieldName = "资源类型", fieldType = (int)SqlDbType.NVarChar },
                    new VonDefinationField() {fieldCode = "Code", fieldName = "编码", fieldType = (int)SqlDbType.VarChar },
                    new VonDefinationField() {fieldCode = "ImageName", fieldName = "资源名称", fieldType = (int)SqlDbType.NVarChar },
                    new VonDefinationField() {fieldCode = "Img", fieldName = "图片", fieldType = (int)SqlDbType.Image },
                    new VonDefinationField() {fieldCode = "Ext", fieldName = "图片类型", fieldType = (int)SqlDbType.VarChar },
                    },
                    Reference = new VonTableReference[]{
                    }
                },
                new VonTableDefination(){
                    tableCode = "Log",
                    tableName = "系统日志",
                    keyField = "",
                    parentField = "",
                    orderField = "",
                    Fields=new VonDefinationField[]{
                    new VonDefinationField() {fieldCode = "LogTime", fieldName = "时间", fieldType = (int)SqlDbType.DateTime },
                    new VonDefinationField() {fieldCode = "EventName", fieldName = "事件", fieldType = (int)SqlDbType.NVarChar },
                    new VonDefinationField() {fieldCode = "Level", fieldName = "等级", fieldType = (int)SqlDbType.Int },
                    new VonDefinationField() {fieldCode = "Content", fieldName = "内容", fieldType = (int)SqlDbType.NVarChar },
                    new VonDefinationField() {fieldCode = "Operator", fieldName = "操作人", fieldType = (int)SqlDbType.NVarChar },
                    },
                    Reference = new VonTableReference[]{
                    }
                },
                new VonTableDefination(){
                    tableCode = "Dim",
                    tableName = "系统维度",
                    keyField = "ID",
                    parentField = "PID",
                    orderField = "DisplayOrder",
                    Fields=new VonDefinationField[]{
                    new VonDefinationField() {fieldCode = "ID", fieldName = "序号", fieldType = (int)SqlDbType.UniqueIdentifier },
                    new VonDefinationField() {fieldCode = "DimName", fieldName = "维度名称", fieldType = (int)SqlDbType.NVarChar },
                    new VonDefinationField() {fieldCode = "PID", fieldName = "父序号", fieldType = (int)SqlDbType.UniqueIdentifier },
                    new VonDefinationField() {fieldCode = "DisplayOrder", fieldName = "显示序号", fieldType = (int)SqlDbType.Int },
                    },
                    Reference = new VonTableReference[]{
                    }
                },
            };
        }
        #endregion
        public override ApplicationDefinationBase AppDefination { get { return Statement.App; } set { Statement.App = value; } }
    }
    #region 成员认证相关
    /// <summary>
    /// 数据及操作控制层
    /// <seealso cref="Von.Web.Business.UserInfo"/>
    /// <seealso cref="Von.Web.Business.UserCtrl"/>
    /// </summary>
    public class SqlIdentityUserAccess : IdentityUserAccess
    {
        #region "User override Methods"
        /// <summary>根据主键 PK_Identity 提取信息</summary>
        ///<param name="ID">序号</param>
        public override IDataReader GetByIdentity(Guid ID)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [ID],[LoginName],[Email],[EmailConfirmed],[PhoneNumber],[PhoneNumberConfirmed],[PasswordHash],[SecurityStamp],[LockoutEnabled],[LockoutEnd],[DisplayName],[AccessFailedCount],[Status],[SysFlag] FROM " + Statement.Owner + Statement.Qualifier + "User WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.UniqueIdentifier).Value = ID;
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>提取 系统登录人员信息 列表</summary>
        public override IDataReader List()
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [ID],[LoginName],[Email],[EmailConfirmed],[PhoneNumber],[PhoneNumberConfirmed],[PasswordHash],[SecurityStamp],[LockoutEnabled],[LockoutEnd],[DisplayName],[AccessFailedCount],[Status],[SysFlag] FROM " + Statement.Owner + Statement.Qualifier + "User Order by LoginName", DBTrans);
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>根据附属信息值 提取成员信息</summary>
        public override IDataReader ListBySubsidiary(string key, string value)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT U.[ID],U.[LoginName],U.[Email],U.[EmailConfirmed],U.[PhoneNumber],U.[PhoneNumberConfirmed],U.[PasswordHash],U.[SecurityStamp],U.[LockoutEnabled],U.[LockoutEnd],U.[DisplayName],U.[AccessFailedCount],U.[Status],U.[SysFlag] FROM " + Statement.Owner + Statement.Qualifier +
                "User U JOIN " + Statement.Owner + Statement.Qualifier + "Subsidiary S ON S.IdentityIdx=U.ID WHERE S.SubName=@Key AND S.SubValue=@Val", DBTrans);
            cmd.Parameters.AddWithValue("@Key", SqlDbType.NVarChar).Value = key;
            cmd.Parameters.AddWithValue("@Val", SqlDbType.NVarChar).Value = value;
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>根据主键 IDX_LoginName 提取信息</summary>
        /// <param name="LoginName">登录名</param>
        public override IDataReader GetByLoginName(string LoginName)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [ID],[LoginName],[Email],[EmailConfirmed],[PhoneNumber],[PhoneNumberConfirmed],[PasswordHash],[SecurityStamp],[LockoutEnabled],[LockoutEnd],[DisplayName],[AccessFailedCount],[Status],[SysFlag] FROM " + Statement.Owner + Statement.Qualifier + "User WHERE LoginName=@LoginName", DBTrans);
            cmd.Parameters.AddWithValue("@LoginName", SqlDbType.NVarChar).Value = LoginName;
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>根据主键 IDX_Email 提取信息</summary>
        /// <param name="Email">Email</param>
        public override IDataReader GetByEmail(string Email)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [ID],[LoginName],[Email],[EmailConfirmed],[PhoneNumber],[PhoneNumberConfirmed],[PasswordHash],[SecurityStamp],[LockoutEnabled],[LockoutEnd],[DisplayName],[AccessFailedCount],[Status],[SysFlag] FROM " + Statement.Owner + Statement.Qualifier + "User WHERE Email=@Email", DBTrans);
            cmd.Parameters.AddWithValue("@Email", SqlDbType.NVarChar).Value = Email;
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>根据主键 IDX_PhoneNumber 提取信息</summary>
        /// <param name="PhoneNumber">手机号</param>
        public override IDataReader GetByPhoneNumber(string PhoneNumber)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [ID],[LoginName],[Email],[EmailConfirmed],[PhoneNumber],[PhoneNumberConfirmed],[PasswordHash],[SecurityStamp],[LockoutEnabled],[LockoutEnd],[DisplayName],[AccessFailedCount],[Status],[SysFlag] FROM " + Statement.Owner + Statement.Qualifier + "User WHERE PhoneNumber=@PhoneNumber", DBTrans);
            cmd.Parameters.AddWithValue("@PhoneNumber", SqlDbType.VarChar).Value = PhoneNumber;
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>检查重复项</summary>
        public override int CheckDoubly(string FieldName, object Value)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT TOP 1 ID FROM " + Statement.Owner + Statement.Qualifier + "User WHERE " + FieldName + "=@FieldName", DBTrans);
            cmd.Parameters.AddWithValue("@FieldName", Value);
            object o = cmd.ExecuteScalar();
            int result = o == null ? 0 : 1;
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        /// <summary>添加User信息</summary>
        /// <param name="ID">序号</param>
        /// <param name="LoginName">登录名</param>
        /// <param name="Email">Email</param>
        /// <param name="EmailConfirmed">Email确认状态</param>
        /// <param name="PhoneNumber">手机号</param>
        /// <param name="PhoneNumberConfirmed">手机确认状态</param>
        /// <param name="PasswordHash">密码</param>
        /// <param name="SecurityStamp">解锁Token</param>
        /// <param name="LockoutEnabled">锁定状态</param>
        /// <param name="LockoutEnd">自动解锁时间</param>
        /// <param name="DisplayName">显示姓名</param>
        /// <param name="AccessFailedCount">登录失败次数</param>
        /// <param name="Status">状态</param>
        /// <param name="SysFlag">系统标识</param>
        public override int Add(Guid ID, string LoginName, string Email, bool EmailConfirmed, string PhoneNumber, bool PhoneNumberConfirmed, string PasswordHash, string SecurityStamp, bool LockoutEnabled, DateTime LockoutEnd, string DisplayName, int AccessFailedCount, string Status, int SysFlag)
        {
            SqlCommand cmd = Statement.InitCommand("INSERT INTO " + Statement.Owner + Statement.Qualifier + "User (ID,LoginName,Email,EmailConfirmed,PhoneNumber,PhoneNumberConfirmed,PasswordHash,SecurityStamp,LockoutEnabled,LockoutEnd,DisplayName,AccessFailedCount,Status,SysFlag)VALUES(@ID,@LoginName,@Email,@EmailConfirmed,@PhoneNumber,@PhoneNumberConfirmed,@PasswordHash,@SecurityStamp,@LockoutEnabled,@LockoutEnd,@DisplayName,@AccessFailedCount,@Status,@SysFlag)", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.UniqueIdentifier).Value = ID;
            cmd.Parameters.AddWithValue("@LoginName", SqlDbType.NVarChar).Value = LoginName;
            cmd.Parameters.AddWithValue("@Email", SqlDbType.NVarChar).Value = Email;
            cmd.Parameters.AddWithValue("@EmailConfirmed", SqlDbType.Bit).Value = EmailConfirmed;
            cmd.Parameters.AddWithValue("@PhoneNumber", SqlDbType.VarChar).Value = PhoneNumber;
            cmd.Parameters.AddWithValue("@PhoneNumberConfirmed", SqlDbType.Bit).Value = PhoneNumberConfirmed;
            cmd.Parameters.AddWithValue("@PasswordHash", SqlDbType.NVarChar).Value = PasswordHash;
            cmd.Parameters.AddWithValue("@SecurityStamp", SqlDbType.NVarChar).Value = SecurityStamp;
            cmd.Parameters.AddWithValue("@LockoutEnabled", SqlDbType.Bit).Value = LockoutEnabled;
            cmd.Parameters.AddWithValue("@LockoutEnd", SqlDbType.DateTime).Value = LockoutEnd;
            cmd.Parameters.AddWithValue("@DisplayName", SqlDbType.NVarChar).Value = DisplayName;
            cmd.Parameters.AddWithValue("@AccessFailedCount", SqlDbType.Int).Value = AccessFailedCount;
            cmd.Parameters.AddWithValue("@Status", SqlDbType.NVarChar).Value = Status;
            cmd.Parameters.AddWithValue("@SysFlag", SqlDbType.Int).Value = SysFlag;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        /// <summary>修改User信息</summary>
        /// <param name="ID">序号</param>
        /// <param name="LoginName">登录名</param>
        /// <param name="Email">Email</param>
        /// <param name="EmailConfirmed">Email确认状态</param>
        /// <param name="PhoneNumber">手机号</param>
        /// <param name="PhoneNumberConfirmed">手机确认状态</param>
        /// <param name="PasswordHash">密码</param>
        /// <param name="SecurityStamp">解锁Token</param>
        /// <param name="LockoutEnabled">锁定状态</param>
        /// <param name="LockoutEnd">自动解锁时间</param>
        /// <param name="DisplayName">显示姓名</param>
        /// <param name="AccessFailedCount">登录失败次数</param>
        /// <param name="Status">状态</param>
        /// <param name="SysFlag">系统标识</param>
        public override int Edit(Guid ID, string LoginName, string Email, bool EmailConfirmed, string PhoneNumber, bool PhoneNumberConfirmed, string DisplayName, int SysFlag)
        {
            SqlCommand cmd = Statement.InitCommand("UPDATE " + Statement.Owner + Statement.Qualifier + "User SET LoginName=@LoginName,Email=@Email,EmailConfirmed=@EmailConfirmed,PhoneNumber=@PhoneNumber,PhoneNumberConfirmed=@PhoneNumberConfirmed,DisplayName=@DisplayName,SysFlag=@SysFlag WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.UniqueIdentifier).Value = ID;
            cmd.Parameters.AddWithValue("@LoginName", SqlDbType.NVarChar).Value = LoginName;
            cmd.Parameters.AddWithValue("@Email", SqlDbType.NVarChar).Value = Email;
            cmd.Parameters.AddWithValue("@EmailConfirmed", SqlDbType.Bit).Value = EmailConfirmed;
            cmd.Parameters.AddWithValue("@PhoneNumber", SqlDbType.VarChar).Value = PhoneNumber;
            cmd.Parameters.AddWithValue("@PhoneNumberConfirmed", SqlDbType.Bit).Value = PhoneNumberConfirmed;
            cmd.Parameters.AddWithValue("@DisplayName", SqlDbType.NVarChar).Value = DisplayName;
            cmd.Parameters.AddWithValue("@SysFlag", SqlDbType.Int).Value = SysFlag;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        /// <summary>修改Identity信息</summary>
        /// <param name="ID">序号</param>
        /// <param name="LoginName">登录名</param>
        /// <param name="Email">Email</param>
        /// <param name="EmailConfirmed">Email确认状态</param>
        /// <param name="PhoneNumber">手机号</param>
        /// <param name="PhoneNumberConfirmed">手机确认状态</param>
        /// <param name="PasswordHash">密码</param>
        /// <param name="SecurityStamp">解锁Token</param>
        /// <param name="LockoutEnabled">锁定状态</param>
        /// <param name="LockoutEnd">自动解锁时间</param>
        /// <param name="DisplayName">显示姓名</param>
        /// <param name="AccessFailedCount">登录失败次数</param>
        /// <param name="Status">状态</param>
        public override int Update(Guid ID, KeyObjectCollection values)
        {
            string SqlText = "";
            SqlCommand cmd = Statement.InitCommand("", DBTrans);
            foreach (KeyObject v in values)
            {
                SqlText += "," + v.Key + "=@" + v.Key;
                cmd.Parameters.AddWithValue("@" + v.Key, v.Obj);
            }
            cmd.CommandText = "UPDATE " + Statement.Owner + Statement.Qualifier + "User SET " + SqlText.Substring(1) + " WHERE ID=@ID";
            cmd.Parameters.AddWithValue("@ID", SqlDbType.UniqueIdentifier).Value = ID;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        /// <summary>修改Identity信息</summary>
        public override int ChangeProperty(Guid ID, string FieldName, object Value)
        {
            SqlCommand cmd = Statement.InitCommand("UPDATE " + Statement.Owner + Statement.Qualifier + "User SET " + FieldName + "=@Val WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.UniqueIdentifier).Value = ID;
            cmd.Parameters.AddWithValue("@Val", Value);
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        /// <summary>根据PK_Identity删除User信息</summary>
        public override int Del(Guid ID)
        {
            SqlCommand cmd = Statement.InitCommand("DELETE FROM " + Statement.Owner + Statement.Qualifier + "User WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.UniqueIdentifier).Value = ID;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }

        public override byte[] GetUserIcon(Guid ID)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [UserIcon] FROM " + Statement.Owner + Statement.Qualifier + "User WHERE ID=@ID", null);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.UniqueIdentifier).Value = ID;
            byte[] b = (byte[])cmd.ExecuteScalar();
            cmd.Connection.Close();
            return b;
        }

        public override int SetUserIcon(Guid ID, Stream file)
        {
            byte[] img = new byte[file.Length];
            file.Read(img, 0, img.Length);
            file.Close();
            SqlCommand cmd = Statement.InitCommand("UPDATE " + Statement.Owner + Statement.Qualifier + "User SET UserIcon = @images where ID=@ID", null);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.UniqueIdentifier).Value = ID;
            cmd.Parameters.Add("@images", SqlDbType.Image).Value = img;
            int cnt = cmd.ExecuteNonQuery();
            cmd.Connection.Close();
            return cnt;
        }
        #endregion
    }
    /// <summary>
    /// 数据及操作控制层
    /// <seealso cref="Von.Web.Business.SubsidiaryInfo"/>
    /// <seealso cref="Von.Web.Business.SubsidiaryCtrl"/>
    /// </summary>
    public class SqlSubsidiaryAccess : SubsidiaryAccess
    {
        #region "Subsidiary override Methods"
        /// <summary>根据主键 PK_Subsidiary 提取信息</summary>
        ///<param name="ID">序号</param>
        public override IDataReader GetBySubsidiary(int ID)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [ID],[IdentityIdx],[SubName],[SubValue] FROM " + Statement.Owner + Statement.Qualifier + "Subsidiary WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.Int).Value = ID;
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>提取 人员附属信息 列表</summary>
        public override IDataReader List()
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [ID],[IdentityIdx],[SubName],[SubValue] FROM " + Statement.Owner + Statement.Qualifier + "Subsidiary ", DBTrans);
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>根据主键 IDX_Subsidiary 提取信息</summary>
        /// <param name="IdentityIdx">人员序号</param>
        /// <param name="SubName">项目名称</param>
        public override IDataReader GetBySubsidiary(Guid IdentityIdx, string SubName)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [ID],[IdentityIdx],[SubName],[SubValue] FROM " + Statement.Owner + Statement.Qualifier + "Subsidiary WHERE IdentityIdx=@IdentityIdx AND SubName=@SubName", DBTrans);
            cmd.Parameters.AddWithValue("@IdentityIdx", SqlDbType.UniqueIdentifier).Value = IdentityIdx;
            cmd.Parameters.AddWithValue("@SubName", SqlDbType.NVarChar).Value = SubName;
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>根据外键 FK_SUBSIDIARY_REF_IDENTITY 提取信息</summary>
        public override IDataReader ListBySUBSIDIARY_REF_IDENTITY(Guid IdentityIdx)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [ID],[IdentityIdx],[SubName],[SubValue] FROM " + Statement.Owner + Statement.Qualifier + "Subsidiary WHERE IdentityIdx=@IdentityIdx", DBTrans);
            cmd.Parameters.AddWithValue("@IdentityIdx", SqlDbType.UniqueIdentifier).Value = IdentityIdx;
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>添加Subsidiary信息</summary>
        /// <param name="ID">序号</param>
        /// <param name="IdentityIdx">人员序号</param>
        /// <param name="SubName">项目名称</param>
        /// <param name="SubValue">项目内容</param>
        public override int Add(Guid IdentityIdx, string SubName, string SubValue)
        {
            SqlCommand cmd = Statement.InitCommand("INSERT INTO " + Statement.Owner + Statement.Qualifier + "Subsidiary (IdentityIdx,SubName,SubValue)OUTPUT INSERTED.ID VALUES(@IdentityIdx,@SubName,@SubValue)", DBTrans);
            cmd.Parameters.AddWithValue("@IdentityIdx", SqlDbType.UniqueIdentifier).Value = IdentityIdx;
            cmd.Parameters.AddWithValue("@SubName", SqlDbType.NVarChar).Value = SubName;
            cmd.Parameters.AddWithValue("@SubValue", SqlDbType.NVarChar).Value = SubValue;
            int result = Convert.ToInt32(cmd.ExecuteScalar());
            if (DBTrans == null)
                cmd.Connection.Close();
            return result;
        }
        /// <summary>修改Subsidiary信息</summary>
        /// <param name="ID">序号</param>
        /// <param name="IdentityIdx">人员序号</param>
        /// <param name="SubName">项目名称</param>
        /// <param name="SubValue">项目内容</param>
        public override int Edit(int ID, Guid IdentityIdx, string SubName, string SubValue)
        {
            SqlCommand cmd = Statement.InitCommand("UPDATE " + Statement.Owner + Statement.Qualifier + "Subsidiary SET IdentityIdx=@IdentityIdx,SubName=@SubName,SubValue=@SubValue WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.Int).Value = ID;
            cmd.Parameters.AddWithValue("@IdentityIdx", SqlDbType.UniqueIdentifier).Value = IdentityIdx;
            cmd.Parameters.AddWithValue("@SubName", SqlDbType.NVarChar).Value = SubName;
            cmd.Parameters.AddWithValue("@SubValue", SqlDbType.NVarChar).Value = SubValue;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        /// <summary>根据PK_Subsidiary删除Subsidiary信息</summary>
        public override int Del(int ID)
        {
            SqlCommand cmd = Statement.InitCommand("DELETE FROM " + Statement.Owner + Statement.Qualifier + "Subsidiary WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.Int).Value = ID;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        /// <summary>根据FK_SUBSIDIARY_REF_IDENTITY删除Subsidiary信息</summary>
        public override int DelIdentity(Guid IdentityIdx)
        {
            SqlCommand cmd = Statement.InitCommand("DELETE FROM " + Statement.Owner + Statement.Qualifier + "Subsidiary WHERE IdentityIdx=@IdentityIdx", DBTrans);
            cmd.Parameters.AddWithValue("@IdentityIdx", SqlDbType.UniqueIdentifier).Value = IdentityIdx;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        /// <summary>根据FK_SUBSIDIARY_REF_IDENTITY删除Subsidiary信息</summary>
        public override int DelIdentity(Guid IdentityIdx, string SubName)
        {
            SqlCommand cmd = Statement.InitCommand("DELETE FROM " + Statement.Owner + Statement.Qualifier + "Subsidiary WHERE IdentityIdx=@IdentityIdx AND SubName=@SubName", DBTrans);
            cmd.Parameters.AddWithValue("@IdentityIdx", SqlDbType.UniqueIdentifier).Value = IdentityIdx;
            cmd.Parameters.AddWithValue("@SubName", SqlDbType.NVarChar).Value = SubName;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        #endregion
    }
    /// <summary>
    /// 数据及操作控制层
    /// <seealso cref="Von.Web.Business.RoleInfo"/>
    /// <seealso cref="Von.Web.Business.RoleCtrl"/>
    /// </summary>
    public class SqlIdentityRoleAccess : IdentityRoleAccess
    {
        #region "Role override Methods"
        /// <summary>根据主键 PK_Role 提取信息</summary>
        ///<param name="ID">序号</param>
        public override IDataReader GetByRole(string RoleName)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [RoleName],[Note],[RoleGroup] FROM " + Statement.Owner + Statement.Qualifier + "Role WHERE RoleName=@RoleName", DBTrans);
            cmd.Parameters.AddWithValue("@RoleName", SqlDbType.NVarChar).Value = RoleName;
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>提取 系统角色信息 列表</summary>
        public override IDataReader List()
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [RoleName],[Note],[RoleGroup] FROM " + Statement.Owner + Statement.Qualifier + "Role ", DBTrans);
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>添加Role信息</summary>
        /// <param name="RoleName">角色名称</param>
        /// <param name="Note">角色描述</param>
        /// <param name="RoleGroup">角色组名称</param>
        public override int Add(string RoleName, string Note, string RoleGroup)
        {
            SqlCommand cmd = Statement.InitCommand("INSERT INTO " + Statement.Owner + Statement.Qualifier + "Role (RoleName,Note,RoleGroup)VALUES(@RoleName,@Note,@RoleGroup)", DBTrans);
            cmd.Parameters.AddWithValue("@RoleName", SqlDbType.NVarChar).Value = RoleName;
            cmd.Parameters.AddWithValue("@Note", SqlDbType.NVarChar).Value = Note;
            cmd.Parameters.AddWithValue("@RoleGroup", SqlDbType.NVarChar).Value = RoleGroup;
            int result = Convert.ToInt32(cmd.ExecuteScalar());
            if (DBTrans == null)
                cmd.Connection.Close();
            return result;
        }
        /// <summary>修改Role信息</summary>
        /// <param name="RoleName">角色名称</param>
        /// <param name="Note">角色描述</param>
        /// <param name="RoleGroup">角色组名称</param>
        public override int Edit(string RoleName, string Note, string RoleGroup)
        {
            SqlCommand cmd = Statement.InitCommand("UPDATE " + Statement.Owner + Statement.Qualifier + "Role SET Note=@Note,RoleGroup=@RoleGroup WHERE RoleName=@RoleName", DBTrans);
            cmd.Parameters.AddWithValue("@RoleName", SqlDbType.NVarChar).Value = RoleName;
            cmd.Parameters.AddWithValue("@Note", SqlDbType.NVarChar).Value = Note;
            cmd.Parameters.AddWithValue("@RoleGroup", SqlDbType.NVarChar).Value = RoleGroup;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        /// <summary>根据PK_Role删除Role信息</summary>
        public override int Del(string RoleName)
        {
            SqlCommand cmd = Statement.InitCommand("DELETE FROM " + Statement.Owner + Statement.Qualifier + "Role WHERE RoleName=@RoleName", DBTrans);
            cmd.Parameters.AddWithValue("@RoleName", SqlDbType.NVarChar).Value = RoleName;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }

        public override IDataReader ListByGroup(string groupName)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [RoleName],[Note],[RoleGroup] FROM " + Statement.Owner + Statement.Qualifier + "Role WHERE groupName=@groupName", DBTrans);
            cmd.Parameters.AddWithValue("@groupName", SqlDbType.NVarChar).Value = groupName;
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }

        public override IDataReader GetGroupNames()
        {
            SqlCommand cmd = Statement.InitCommand("SELECT DISTINCT [RoleGroup] FROM " + Statement.Owner + Statement.Qualifier + "Role", DBTrans);
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        #endregion
    }
    /// <summary>
    /// 数据及操作控制层
    /// <seealso cref="Von.Web.Business.UserRoleInfo"/>
    /// <seealso cref="Von.Web.Business.UserRoleCtrl"/>
    /// </summary>
    public class SqlUserRoleAccess : UserRoleAccess
    {
        #region "UserRole override Methods"
        /// <summary>根据主键 PK_UserRole 提取信息</summary>
        ///<param name="ID">序号</param>
        public override IDataReader GetByUserRole(int ID)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [ID],[UserIdx],[RoleName] FROM " + Statement.Owner + Statement.Qualifier + "UserRole WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.Int).Value = ID;
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>提取 人员角色关联 列表</summary>
        public override IDataReader List()
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [ID],[UserIdx],[RoleName] FROM " + Statement.Owner + Statement.Qualifier + "UserRole ", DBTrans);
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>根据主键 IDX_User 提取信息</summary>
        /// <param name="UserIdx">人员序号</param>
        public override IDataReader ListByUser(Guid UserIdx)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [ID],[UserIdx],[RoleName] FROM " + Statement.Owner + Statement.Qualifier + "UserRole WHERE UserIdx=@UserIdx", DBTrans);
            cmd.Parameters.AddWithValue("@UserIdx", SqlDbType.UniqueIdentifier).Value = UserIdx;
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>根据主键 IDX_Role 提取信息</summary>
        /// <param name="RoleName">角色名称</param>
        public override IDataReader ListByRole(string RoleName)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [ID],[UserIdx],[RoleName] FROM " + Statement.Owner + Statement.Qualifier + "UserRole WHERE RoleName=@RoleName", DBTrans);
            cmd.Parameters.AddWithValue("@RoleName", SqlDbType.NVarChar).Value = RoleName;
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>根据外键 FK_IDENTITY_REF_ROLE 提取信息</summary>
        public override IDataReader ListByIDENTITY_REF_ROLE(Guid UserIdx)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [ID],[UserIdx],[RoleName] FROM " + Statement.Owner + Statement.Qualifier + "UserRole WHERE UserIdx=@UserIdx", DBTrans);
            cmd.Parameters.AddWithValue("@UserIdx", SqlDbType.UniqueIdentifier).Value = UserIdx;
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>根据外键 FK_ROLE_REF_IDENTITY 提取信息</summary>
        public override IDataReader ListByROLE_REF_IDENTITY(string RoleName)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [ID],[UserIdx],[RoleName] FROM " + Statement.Owner + Statement.Qualifier + "UserRole WHERE RoleName=@RoleName", DBTrans);
            cmd.Parameters.AddWithValue("@RoleName", SqlDbType.NVarChar).Value = RoleName;
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>添加UserRole信息</summary>
        /// <param name="ID">序号</param>
        /// <param name="UserIdx">人员序号</param>
        /// <param name="RoleName">角色名称</param>
        public override int Add(Guid UserIdx, string RoleName)
        {
            SqlCommand cmd = Statement.InitCommand("INSERT INTO " + Statement.Owner + Statement.Qualifier + "UserRole (UserIdx,RoleName)VALUES(@UserIdx,@RoleName)", DBTrans);
            cmd.Parameters.AddWithValue("@UserIdx", SqlDbType.UniqueIdentifier).Value = UserIdx;
            cmd.Parameters.AddWithValue("@RoleName", SqlDbType.NVarChar).Value = RoleName;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        /// <summary>修改UserRole信息</summary>
        /// <param name="ID">序号</param>
        /// <param name="UserIdx">人员序号</param>
        /// <param name="RoleName">角色名称</param>
        public override int Edit(int ID, Guid UserIdx, string RoleName)
        {
            SqlCommand cmd = Statement.InitCommand("UPDATE " + Statement.Owner + Statement.Qualifier + "UserRole SET UserIdx=@UserIdx,RoleName=@RoleName WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.Int).Value = ID;
            cmd.Parameters.AddWithValue("@UserIdx", SqlDbType.UniqueIdentifier).Value = UserIdx;
            cmd.Parameters.AddWithValue("@RoleName", SqlDbType.NVarChar).Value = RoleName;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        /// <summary>根据PK_UserRole删除UserRole信息</summary>
        public override int Del(int ID)
        {
            SqlCommand cmd = Statement.InitCommand("DELETE FROM " + Statement.Owner + Statement.Qualifier + "UserRole WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.Int).Value = ID;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        /// <summary>根据FK_IDENTITY_REF_ROLE删除UserRole信息</summary>
        public override int DelUser(Guid UserIdx)
        {
            SqlCommand cmd = Statement.InitCommand("DELETE FROM " + Statement.Owner + Statement.Qualifier + "UserRole WHERE UserIdx=@UserIdx", DBTrans);
            cmd.Parameters.AddWithValue("@UserIdx", SqlDbType.UniqueIdentifier).Value = UserIdx;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        /// <summary>根据FK_ROLE_REF_IDENTITY删除UserRole信息</summary>
        public override int DelRoleName(string RoleName)
        {
            SqlCommand cmd = Statement.InitCommand("DELETE FROM " + Statement.Owner + Statement.Qualifier + "UserRole WHERE RoleName=@RoleName", DBTrans);
            cmd.Parameters.AddWithValue("@RoleName", SqlDbType.NVarChar).Value = RoleName;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        #endregion
    }
    /// <summary>
    /// 数据及操作控制层
    /// <seealso cref="Von.Web.Business.RightInfo"/>
    /// <seealso cref="Von.Web.Business.RightCtrl"/>
    /// </summary>
    public class SqlRightAccess : RightAccess
    {
        #region "Right override Methods"
        /// <summary>根据主键 PK_TabRole 提取信息</summary>
        ///<param name="ID">序号</param>
        public override IDataReader GetByTabRole(int ID)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [ID],[RoleName],[DestIdx],[Kind] FROM " + Statement.Owner + Statement.Qualifier + "Right WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.Int).Value = ID;
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>提取 权限控制 列表</summary>
        public override IDataReader ListByUser(Guid ID, int Kind)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT R.[ID],R.[RoleName],R.[DestIdx],R.[Kind] FROM " + Statement.Owner + Statement.Qualifier + "Right R JOIN " +
                Statement.Owner + Statement.Qualifier + "UserRole U ON U.RoleName=R.RoleName AND U.UserIdx=@ID " + (Kind > 0 ? "WHERE R.Kind=" + Kind.ToString() : ""), DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.UniqueIdentifier).Value = ID;
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>根据主键 IDX_DestIdx 提取信息</summary>
        /// <param name="DestIdx">控制目标序号</param>
        public override IDataReader ListByDestIdx(Guid DestIdx)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [ID],[RoleName],[DestIdx],[Kind] FROM " + Statement.Owner + Statement.Qualifier + "Right WHERE DestIdx=@DestIdx", DBTrans);
            cmd.Parameters.AddWithValue("@DestIdx", SqlDbType.UniqueIdentifier).Value = DestIdx;
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>根据外键 FK_RIGHT_REF_ROLE 提取信息</summary>
        public override IDataReader ListByRIGHT_REF_ROLE(string RoleName)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [ID],[RoleName],[DestIdx],[Kind] FROM " + Statement.Owner + Statement.Qualifier + "Right WHERE RoleName=@RoleName", DBTrans);
            cmd.Parameters.AddWithValue("@RoleName", SqlDbType.NVarChar).Value = RoleName;
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>添加Right信息</summary>
        /// <param name="ID">序号</param>
        /// <param name="RoleName">角色名称</param>
        /// <param name="DestIdx">控制目标序号</param>
        /// <param name="Kind">控制类型</param>
        public override int Add(string RoleName, Guid DestIdx, int Kind)
        {
            SqlCommand cmd = Statement.InitCommand("INSERT INTO " + Statement.Owner + Statement.Qualifier + "Right (RoleName,DestIdx,Kind)OUTPUT INSERTED.ID VALUES(@RoleName,@DestIdx,@Kind)", DBTrans);
            cmd.Parameters.AddWithValue("@RoleName", SqlDbType.NVarChar).Value = RoleName;
            cmd.Parameters.AddWithValue("@DestIdx", SqlDbType.UniqueIdentifier).Value = DestIdx;
            cmd.Parameters.AddWithValue("@Kind", SqlDbType.Int).Value = Kind;
            int result = Convert.ToInt32(cmd.ExecuteScalar());
            if (DBTrans == null)
                cmd.Connection.Close();
            return result;
        }
        /// <summary>修改Right信息</summary>
        /// <param name="ID">序号</param>
        /// <param name="RoleName">角色名称</param>
        /// <param name="DestIdx">控制目标序号</param>
        /// <param name="Kind">控制类型</param>
        public override int Edit(int ID, string RoleName, Guid DestIdx, int Kind)
        {
            SqlCommand cmd = Statement.InitCommand("UPDATE " + Statement.Owner + Statement.Qualifier + "Right SET RoleName=@RoleName,DestIdx=@DestIdx,Kind=@Kind WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.Int).Value = ID;
            cmd.Parameters.AddWithValue("@RoleName", SqlDbType.NVarChar).Value = RoleName;
            cmd.Parameters.AddWithValue("@DestIdx", SqlDbType.UniqueIdentifier).Value = DestIdx;
            cmd.Parameters.AddWithValue("@Kind", SqlDbType.Int).Value = Kind;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        /// <summary>根据PK_TabRole删除Right信息</summary>
        public override int Del(int ID)
        {
            SqlCommand cmd = Statement.InitCommand("DELETE FROM " + Statement.Owner + Statement.Qualifier + "Right WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.Int).Value = ID;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        /// <summary>根据FK_RIGHT_REF_ROLE删除Right信息</summary>
        public override int DelRoleName(string RoleName)
        {
            SqlCommand cmd = Statement.InitCommand("DELETE FROM " + Statement.Owner + Statement.Qualifier + "Right WHERE RoleName=@RoleName", DBTrans);
            cmd.Parameters.AddWithValue("@RoleName", SqlDbType.NVarChar).Value = RoleName;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        #endregion
    }
    #endregion
    #region 系统管理工具
    /// <summary>
    /// 数据及操作控制层
    /// <seealso cref="Von.Portal.Business.MenuInfo"/>
    /// <seealso cref="Von.Portal.Business.MenuCtrl"/>
    /// </summary>
    public class SqlMenuAccess : MenuAccess
    {
        #region "Menu override Methods"
        /// <summary>根据主键 PK_Menu 提取信息</summary>
        ///<param name="ID">序号</param>
        public override IDataReader GetByMenu(Guid ID)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [ID],[MenuName],[PID],[MenuClass],[iconFilename],[MenuData],[DisplayOrder] FROM " + Statement.Owner + Statement.Qualifier + "Menu WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.UniqueIdentifier).Value = ID;
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>提取 站点菜单 列表</summary>
        public override IDataReader List()
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [ID],[MenuName],[PID],[MenuClass],[iconFilename],[MenuData],[DisplayOrder] FROM " + Statement.Owner + Statement.Qualifier + "Menu ORDER BY [PID],[DisplayOrder]", DBTrans);
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>根据索引 IDX_Menu_PID 提取信息</summary>
        /// <param name="PID">父节点</param>
        public override IDataReader ListByMenu_PID(Guid PID)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [ID],[MenuName],[PID],[MenuClass],[iconFilename],[MenuData],[DisplayOrder] FROM " + Statement.Owner + Statement.Qualifier + "Menu WHERE PID=@PID ORDER BY [DisplayOrder]", DBTrans);
            cmd.Parameters.AddWithValue("@PID", SqlDbType.UniqueIdentifier).Value = PID;
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>添加Menu信息</summary>
        /// <param name="ID">序号</param>
        /// <param name="MenuName">菜单名称</param>
        /// <param name="PID">父节点</param>
        /// <param name="MenuClass">菜单样式</param>
        /// <param name="iconFilename">菜单图标</param>
        /// <param name="MenuData">菜单内容</param>
        public override int Add(Guid ID, string MenuName, Guid PID, string MenuClass, string iconFilename, string MenuData, int DisplayOrder)
        {
            SqlCommand cmd = Statement.InitCommand("INSERT INTO " + Statement.Owner + Statement.Qualifier + "Menu (ID,MenuName,PID,MenuClass,iconFilename,MenuData,DisplayOrder)VALUES(@ID,@MenuName,@PID,@MenuClass,@iconFilename,@MenuData,@DisplayOrder)", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.UniqueIdentifier).Value = ID;
            cmd.Parameters.AddWithValue("@MenuName", SqlDbType.NVarChar).Value = MenuName;
            cmd.Parameters.AddWithValue("@PID", SqlDbType.UniqueIdentifier).Value = PID;
            cmd.Parameters.AddWithValue("@MenuClass", SqlDbType.NVarChar).Value = MenuClass;
            cmd.Parameters.AddWithValue("@iconFilename", SqlDbType.NVarChar).Value = iconFilename;
            cmd.Parameters.AddWithValue("@MenuData", SqlDbType.NVarChar).Value = MenuData;
            cmd.Parameters.AddWithValue("@DisplayOrder", SqlDbType.Int).Value = DisplayOrder;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null)
                cmd.Connection.Close();
            return result;
        }
        /// <summary>修改Menu信息</summary>
        /// <param name="ID">序号</param>
        /// <param name="MenuName">菜单名称</param>
        /// <param name="PID">父节点</param>
        /// <param name="MenuClass">菜单样式</param>
        /// <param name="iconFilename">菜单图标</param>
        /// <param name="MenuData">菜单内容</param>
        public override int Edit(Guid ID, string MenuName, Guid PID, string MenuClass, string iconFilename, string MenuData, int DisplayOrder)
        {
            SqlCommand cmd = Statement.InitCommand("UPDATE " + Statement.Owner + Statement.Qualifier + "Menu SET MenuName=@MenuName,PID=@PID,MenuClass=@MenuClass,iconFilename=@iconFilename,MenuData=@MenuData,DisplayOrder=@DisplayOrder WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.UniqueIdentifier).Value = ID;
            cmd.Parameters.AddWithValue("@MenuName", SqlDbType.NVarChar).Value = MenuName;
            cmd.Parameters.AddWithValue("@PID", SqlDbType.UniqueIdentifier).Value = PID;
            cmd.Parameters.AddWithValue("@MenuClass", SqlDbType.NVarChar).Value = MenuClass;
            cmd.Parameters.AddWithValue("@iconFilename", SqlDbType.NVarChar).Value = iconFilename;
            cmd.Parameters.AddWithValue("@MenuData", SqlDbType.NVarChar).Value = MenuData;
            cmd.Parameters.AddWithValue("@DisplayOrder", SqlDbType.Int).Value = DisplayOrder;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        /// <summary>根据PK_Menu删除Menu信息</summary>
        public override int Del(Guid ID)
        {
            Move(ID, int.MaxValue);
            SqlCommand cmd = Statement.InitCommand("DELETE FROM " + Statement.Owner + Statement.Qualifier + "Menu WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.UniqueIdentifier).Value = ID;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }

        public override int Move(Guid ID, int newOrder)
        {
            SqlCommand cmd = Statement.InitCommand("MOVE_MENU", DBTrans);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@ID", SqlDbType.UniqueIdentifier).Value = ID;
            cmd.Parameters.AddWithValue("@NewOrder", SqlDbType.UniqueIdentifier).Value = newOrder;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }

        public override IDataReader ListByMenuWithRight(Guid PID, string RoleName)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT M.[ID],M.[MenuName],M.[PID],M.[DisplayOrder],IsNull(R.ID,0) FROM Von_Menu M LEFT JOIN Von_Right R ON R.DestIdx = M.ID AND R.RoleName=@RoleName WHERE PID=@PID ORDER BY[DisplayOrder]", DBTrans);
            cmd.Parameters.AddWithValue("@RoleName", SqlDbType.NVarChar).Value = RoleName;
            cmd.Parameters.AddWithValue("@PID", SqlDbType.UniqueIdentifier).Value = PID;
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        #endregion
    }
    /// <summary>
    /// 数据及操作控制层
    /// <seealso cref="Von.Web.Business.TicketNoInfo"/>
    /// <seealso cref="Von.Web.Business.TicketNoCtrl"/>
    /// </summary>
    public class SqlTicketNoAccess : TicketNoAccess
    {
        #region "TicketNo override Methods"
        /// <summary>根据主键 PK_TicketNo 提取信息</summary>
        ///<param name="ID">序号</param>
        public override IDataReader GetByTicketNo(string RuleName)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [RuleName],[LastTime],[CurrentID],[Kind],[NumLength],[Rule] FROM " + Statement.Owner + Statement.Qualifier + "TicketNo WHERE RuleName=@RuleName", DBTrans);
            cmd.Parameters.AddWithValue("@RuleName", SqlDbType.NVarChar).Value = RuleName;
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>提取 票证编码规则 列表</summary>
        public override IDataReader List()
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [RuleName],[LastTime],[CurrentID],[Kind],[NumLength],[Rule] FROM " + Statement.Owner + Statement.Qualifier + "TicketNo ", DBTrans);
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>添加TicketNo信息</summary>
        /// <param name="RuleName">规则名称</param>
        /// <param name="LastTime">最后取值时间</param>
        /// <param name="CurrentID">当前序号</param>
        /// <param name="Kind">变更类型</param>
        /// <param name="NumLength">编码长度</param>
        /// <param name="Rule">编码规则</param>
        public override int Add(string RuleName, DateTime LastTime, int CurrentID, int Kind, int NumLength, string Rule)
        {
            SqlCommand cmd = Statement.InitCommand("INSERT INTO " + Statement.Owner + Statement.Qualifier + "TicketNo (RuleName,LastTime,CurrentID,Kind,NumLength,[Rule])VALUES(@RuleName,@LastTime,@CurrentID,@Kind,@NumLength,@Rule)", DBTrans);
            cmd.Parameters.AddWithValue("@RuleName", SqlDbType.NVarChar).Value = RuleName;
            cmd.Parameters.AddWithValue("@LastTime", SqlDbType.DateTime).Value = LastTime;
            cmd.Parameters.AddWithValue("@CurrentID", SqlDbType.Int).Value = CurrentID;
            cmd.Parameters.AddWithValue("@Kind", SqlDbType.Int).Value = Kind;
            cmd.Parameters.AddWithValue("@NumLength", SqlDbType.Int).Value = NumLength;
            cmd.Parameters.AddWithValue("@Rule", SqlDbType.VarChar).Value = Rule;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        /// <summary>修改TicketNo信息</summary>
        /// <param name="RuleName">规则名称</param>
        /// <param name="LastTime">最后取值时间</param>
        /// <param name="CurrentID">当前序号</param>
        /// <param name="Kind">变更类型</param>
        /// <param name="NumLength">编码长度</param>
        /// <param name="Rule">编码规则</param>
        public override int Edit(string RuleName, DateTime LastTime, int CurrentID, int Kind, int NumLength, string Rule)
        {
            SqlCommand cmd = Statement.InitCommand("UPDATE " + Statement.Owner + Statement.Qualifier + "TicketNo SET LastTime=@LastTime,CurrentID=@CurrentID,Kind=@Kind,NumLength=@NumLength,[Rule]=@Rule WHERE RuleName=@RuleName", DBTrans);
            cmd.Parameters.AddWithValue("@RuleName", SqlDbType.NVarChar).Value = RuleName;
            cmd.Parameters.AddWithValue("@LastTime", SqlDbType.DateTime).Value = LastTime;
            cmd.Parameters.AddWithValue("@CurrentID", SqlDbType.Int).Value = CurrentID;
            cmd.Parameters.AddWithValue("@Kind", SqlDbType.Int).Value = Kind;
            cmd.Parameters.AddWithValue("@NumLength", SqlDbType.Int).Value = NumLength;
            cmd.Parameters.AddWithValue("@Rule", SqlDbType.VarChar).Value = Rule;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        /// <summary>根据PK_TicketNo删除TicketNo信息</summary>
        public override int Del(string RuleName)
        {
            SqlCommand cmd = Statement.InitCommand("DELETE FROM " + Statement.Owner + Statement.Qualifier + "TicketNo WHERE RuleName=@RuleName", DBTrans);
            cmd.Parameters.AddWithValue("@RuleName", SqlDbType.NVarChar).Value = RuleName;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        #endregion
    }
    /// <summary>
    /// 数据及操作控制层
    /// <seealso cref="Von.Web.Business.StateFlowInfo"/>
    /// <seealso cref="Von.Web.Business.StateFlowCtrl"/>
    /// </summary>
    public class SqlStateFlowAccess : StateFlowAccess
    {
        #region "StateFlow override Methods"
        /// <summary>根据主键 PK_StateFlow 提取信息</summary>
        ///<param name="ID">序号</param>
        public override IDataReader GetByStateFlow(Guid ID)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [ID],[FlowName],[Kind],[Param],[Status],[Creator],[CreateTime],[Modifier],[Modifidate] FROM " + Statement.Owner + Statement.Qualifier + "StateFlow WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.UniqueIdentifier).Value = ID;
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>根据分类和名称提取信息</summary>
        public override IDataReader GetByStateFlow(string Kind, string FlowName)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [ID],[FlowName],[Kind],[Param],[Status],[Creator],[CreateTime],[Modifier],[Modifidate] FROM " + Statement.Owner + Statement.Qualifier + "StateFlow WHERE FlowName=@FlowName AND Kind=@Kind", DBTrans);
            cmd.Parameters.AddWithValue("@FlowName", SqlDbType.NVarChar).Value = FlowName;
            cmd.Parameters.AddWithValue("@Kind", SqlDbType.NVarChar).Value = Kind;
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>提取 审批流 列表</summary>
        public override IDataReader List()
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [ID],[FlowName],[Kind],[Param],[Status],[Creator],[CreateTime],[Modifier],[Modifidate] FROM " + Statement.Owner + Statement.Qualifier + "StateFlow ", DBTrans);
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>添加StateFlow信息</summary>
        /// <param name="ID">序号</param>
        /// <param name="FlowName">流程名称</param>
        /// <param name="Kind">业务分类</param>
        /// <param name="Param">流程参数</param>
        /// <param name="Status">状态</param>
        /// <param name="Creator">创建人</param>
        /// <param name="CreateTime">创建时间</param>
        /// <param name="Modifier">修改人</param>
        /// <param name="Modifidate">修改时间</param>
        public override int Add(Guid ID, string FlowName, string Kind, string Param, string Status, Guid Creator, DateTime CreateTime, Guid Modifier, DateTime Modifidate)
        {
            SqlCommand cmd = Statement.InitCommand("INSERT INTO " + Statement.Owner + Statement.Qualifier + "StateFlow(ID,FlowName,Kind,Param,Status,Creator,CreateTime,Modifier,Modifidate)VALUES(@ID,@FlowName,@Kind,@Param,@Status,@Creator,@CreateTime,@Modifier,@Modifidate)", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.UniqueIdentifier).Value = ID;
            cmd.Parameters.AddWithValue("@FlowName", SqlDbType.NVarChar).Value = FlowName;
            cmd.Parameters.AddWithValue("@Kind", SqlDbType.NVarChar).Value = Kind;
            cmd.Parameters.AddWithValue("@Param", SqlDbType.NVarChar).Value = Param;
            cmd.Parameters.AddWithValue("@Status", SqlDbType.NVarChar).Value = Status;
            cmd.Parameters.AddWithValue("@Creator", SqlDbType.UniqueIdentifier).Value = Creator;
            cmd.Parameters.AddWithValue("@CreateTime", SqlDbType.DateTime).Value = CreateTime;
            cmd.Parameters.AddWithValue("@Modifier", SqlDbType.UniqueIdentifier).Value = Modifier;
            cmd.Parameters.AddWithValue("@Modifidate", SqlDbType.DateTime).Value = Modifidate;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        /// <summary>修改StateFlow信息</summary>
        /// <param name="ID">序号</param>
        /// <param name="FlowName">流程名称</param>
        /// <param name="Kind">业务分类</param>
        /// <param name="Param">流程参数</param>
        /// <param name="Status">状态</param>
        /// <param name="Creator">创建人</param>
        /// <param name="CreateTime">创建时间</param>
        /// <param name="Modifier">修改人</param>
        /// <param name="Modifidate">修改时间</param>
        public override int Edit(Guid ID, string FlowName, string Kind, string Param, string Status, Guid Creator, DateTime CreateTime, Guid Modifier, DateTime Modifidate)
        {
            SqlCommand cmd = Statement.InitCommand("UPDATE " + Statement.Owner + Statement.Qualifier + "StateFlow SET FlowName=@FlowName,Kind=@Kind,Param=@Param,Status=@Status,Creator=@Creator,CreateTime=@CreateTime,Modifier=@Modifier,Modifidate=@Modifidate WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.UniqueIdentifier).Value = ID;
            cmd.Parameters.AddWithValue("@FlowName", SqlDbType.NVarChar).Value = FlowName;
            cmd.Parameters.AddWithValue("@Kind", SqlDbType.NVarChar).Value = Kind;
            cmd.Parameters.AddWithValue("@Param", SqlDbType.NVarChar).Value = Param;
            cmd.Parameters.AddWithValue("@Status", SqlDbType.NVarChar).Value = Status;
            cmd.Parameters.AddWithValue("@Creator", SqlDbType.UniqueIdentifier).Value = Creator;
            cmd.Parameters.AddWithValue("@CreateTime", SqlDbType.DateTime).Value = CreateTime;
            cmd.Parameters.AddWithValue("@Modifier", SqlDbType.UniqueIdentifier).Value = Modifier;
            cmd.Parameters.AddWithValue("@Modifidate", SqlDbType.DateTime).Value = Modifidate;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        /// <summary>根据PK_StateFlow删除StateFlow信息</summary>
        public override int Del(Guid ID)
        {
            SqlCommand cmd = Statement.InitCommand("DELETE FROM " + Statement.Owner + Statement.Qualifier + "StateFlow WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.UniqueIdentifier).Value = ID;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        /// <summary>更改设计内容，含流程图</summary>
        public override int UpdateSetting(Guid ID, string Setting)
        {
            SqlCommand cmd = Statement.InitCommand("UPDATE " + Statement.Owner + Statement.Qualifier + "StateFlow SET Setting=@Setting WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.UniqueIdentifier).Value = ID;
            cmd.Parameters.AddWithValue("@Setting", SqlDbType.NText).Value = Setting;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        /// <summary>获取设计内容，含流程图</summary>
        public override string LoadSetting(Guid ID)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT Setting FROM " + Statement.Owner + Statement.Qualifier + "StateFlow WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.UniqueIdentifier).Value = ID;
            object result = cmd.ExecuteScalar();
            if (DBTrans == null) cmd.Connection.Close();
            if (result == null) return "";
            return result.ToString();
        }
        #endregion
    }
    /// <summary>
    /// 数据及操作控制层
    /// <seealso cref="Von.Web.Business.StateFlowItemInfo"/>
    /// <seealso cref="Von.Web.Business.StateFlowItemCtrl"/>
    /// </summary>
    public class SqlStateFlowItemAccess : StateFlowItemAccess
    {
        #region "StateFlowItem override Methods"
        /// <summary>根据主键 PK_StateFlowItem 提取信息</summary>
        ///<param name="ID">序号</param>
        public override IDataReader GetByStateFlowItem(Guid ID)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [ID],[FlowIdx],[InStatus],[MethodName],[Style],[OutStatus],[OutData] FROM " + Statement.Owner + Statement.Qualifier + "StateFlowItem WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.UniqueIdentifier).Value = ID;
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>提取 审批流节点 列表</summary>
        public override IDataReader List()
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [ID],[FlowIdx],[InStatus],[MethodName],[Style],[OutStatus],[OutData] FROM " + Statement.Owner + Statement.Qualifier + "StateFlowItem ", DBTrans);
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>根据主键 IDX_StateFlowItem 提取信息</summary>
        /// <param name="FlowIdx">审批方案索引</param>
        public override IDataReader ListByStateFlowItem(Guid FlowIdx)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [ID],[FlowIdx],[InStatus],[MethodName],[Style],[OutStatus],[OutData] FROM " + Statement.Owner + Statement.Qualifier + "StateFlowItem WHERE FlowIdx=@FlowIdx", DBTrans);
            cmd.Parameters.AddWithValue("@FlowIdx", SqlDbType.UniqueIdentifier).Value = FlowIdx;
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>根据外键 FK_ITEM_REF_STATEFLOW 提取信息</summary>
        public override IDataReader ListByITEM_REF_STATEFLOW(Guid FlowIdx)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [ID],[FlowIdx],[InStatus],[MethodName],[Style],[OutStatus],[OutData] FROM " + Statement.Owner + Statement.Qualifier + "StateFlowItem WHERE FlowIdx=@FlowIdx", DBTrans);
            cmd.Parameters.AddWithValue("@FlowIdx", SqlDbType.UniqueIdentifier).Value = FlowIdx;
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>添加StateFlowItem信息</summary>
        /// <param name="ID">序号</param>
        /// <param name="FlowIdx">审批方案索引</param>
        /// <param name="InCondition">进入条件</param>
        /// <param name="InStatus">进入状态</param>
        /// <param name="MethodName">处理方法</param>
        /// <param name="OutStatus">处理结果</param>
        /// <param name="OutEvent">处理后事件</param>
        public override int Add(Guid ID, Guid FlowIdx, string InStatus, string MethodName, string Style, string OutStatus, string OutData)
        {
            SqlCommand cmd = Statement.InitCommand("INSERT INTO " + Statement.Owner + Statement.Qualifier + "StateFlowItem (ID,FlowIdx,InStatus,MethodName,Style,OutStatus,OutData)VALUES(@ID,@FlowIdx,@InStatus,@MethodName,@Style,@OutStatus,@OutData)", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.UniqueIdentifier).Value = ID;
            cmd.Parameters.AddWithValue("@FlowIdx", SqlDbType.UniqueIdentifier).Value = FlowIdx;
            cmd.Parameters.AddWithValue("@InStatus", SqlDbType.NVarChar).Value = InStatus;
            cmd.Parameters.AddWithValue("@MethodName", SqlDbType.NVarChar).Value = MethodName;
            cmd.Parameters.AddWithValue("@Style", SqlDbType.NVarChar).Value = Style;
            cmd.Parameters.AddWithValue("@OutStatus", SqlDbType.NVarChar).Value = OutStatus;
            cmd.Parameters.AddWithValue("@OutData", SqlDbType.NVarChar).Value = OutData;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        /// <summary>修改StateFlowItem信息</summary>
        /// <param name="ID">序号</param>
        /// <param name="FlowIdx">审批方案索引</param>
        /// <param name="InCondition">进入条件</param>
        /// <param name="InStatus">进入状态</param>
        /// <param name="MethodName">处理方法</param>
        /// <param name="OutStatus">处理结果</param>
        /// <param name="OutEvent">处理后事件</param>
        public override int Edit(Guid ID, Guid FlowIdx, string InStatus, string MethodName, string Style, string OutStatus, string OutData)
        {
            SqlCommand cmd = Statement.InitCommand("UPDATE " + Statement.Owner + Statement.Qualifier + "StateFlowItem SET FlowIdx=@FlowIdx,InStatus=@InStatus,MethodName=@MethodName,Style=@Style,OutStatus=@OutStatus,OutData=@OutData WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.UniqueIdentifier).Value = ID;
            cmd.Parameters.AddWithValue("@FlowIdx", SqlDbType.UniqueIdentifier).Value = FlowIdx;
            cmd.Parameters.AddWithValue("@InStatus", SqlDbType.NVarChar).Value = InStatus;
            cmd.Parameters.AddWithValue("@MethodName", SqlDbType.NVarChar).Value = MethodName;
            cmd.Parameters.AddWithValue("@Style", SqlDbType.NVarChar).Value = Style;
            cmd.Parameters.AddWithValue("@OutStatus", SqlDbType.NVarChar).Value = OutStatus;
            cmd.Parameters.AddWithValue("@OutData", SqlDbType.NVarChar).Value = OutData;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        /// <summary>根据PK_StateFlowItem删除StateFlowItem信息</summary>
        public override int Del(Guid ID)
        {
            SqlCommand cmd = Statement.InitCommand("DELETE FROM " + Statement.Owner + Statement.Qualifier + "StateFlowItem WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.UniqueIdentifier).Value = ID;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        /// <summary>根据FK_ITEM_REF_STATEFLOW删除StateFlowItem信息</summary>
        public override int DelFlow(Guid FlowIdx)
        {
            SqlCommand cmd = Statement.InitCommand("DELETE FROM " + Statement.Owner + Statement.Qualifier + "StateFlowItem WHERE FlowIdx=@FlowIdx", DBTrans);
            cmd.Parameters.AddWithValue("@FlowIdx", SqlDbType.UniqueIdentifier).Value = FlowIdx;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }

        public override IDataReader ListMethods(Guid FlowIdx, string CurrentStatus)
        {
            throw new NotImplementedException();
        }

        public override IDataReader GetByStateFlowItemByMethod(Guid iD, string method)
        {
            throw new NotImplementedException();
        }
        #endregion
    }
    #region "审批流节点状态信息数据库访问基类声明"
    /// <summary>
    /// 数据及操作控制层
    /// </summary>
    /// <seealso cref="Join.Web.Models.StateFlowStatusInfo"/>
    /// <seealso cref="Join.Web.Operators.StateFlowStatusCtrl"/>
    public class SqlStateFlowStatusAccess : StateFlowStatusAccess
    {
        #region "StateFlowStatus Abstract Methods"
        /// <summary>提取 审批流节点状态 列表</summary>
        public override IDataReader List()
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [FlowIdx],[Condition],[Status] FROM " + Statement.Owner + Statement.Qualifier + "StateFlowStatus ", DBTrans);
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>查询 审批流节点状态 列表</summary>
        public override IDataReader Search(JObject ConditionJson)
        {
            SqlCommand cmd = Statement.InitCommand("", DBTrans);
            string whereSql = GereralSearchSql(ConditionJson, addParameter);
            cmd.CommandText = "SELECT [FlowIdx],[Condition],[Status] FROM " + Statement.Owner + Statement.Qualifier + "StateFlowStatus" + (whereSql == "" ? "" : " WHERE " + whereSql.Substring(5));
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
            void addParameter(string key, object val)
            {
                cmd.Parameters.AddWithValue("@" + key, val);
            }
        }
        /// <summary>根据主键 IDX_StateFlowItem 提取信息</summary>
        public override IDataReader GetByStateFlowItem(Guid FlowIdx, string Status)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [FlowIdx],[Condition],[Status] FROM " + Statement.Owner + Statement.Qualifier + "StateFlowStatus WHERE FlowIdx=@FlowIdx AND Status=@Status", DBTrans);
            cmd.Parameters.AddWithValue("@FlowIdx", SqlDbType.UniqueIdentifier).Value = FlowIdx;
            cmd.Parameters.AddWithValue("@Status", SqlDbType.NVarChar).Value = Status;
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>添加StateFlowStatus信息</summary>
        public override int Add(Guid FlowIdx, string Condition, string Status)
        {
            SqlCommand cmd = Statement.InitCommand("INSERT INTO " + Statement.Owner + Statement.Qualifier + "StateFlowStatus ([FlowIdx],[Condition],[Status])VALUES(@FlowIdx,@Condition,@Status)", DBTrans);
            cmd.Parameters.AddWithValue("@FlowIdx", SqlDbType.UniqueIdentifier).Value = FlowIdx;
            cmd.Parameters.AddWithValue("@Condition", SqlDbType.NVarChar).Value = Condition;
            cmd.Parameters.AddWithValue("@Status", SqlDbType.NVarChar).Value = Status;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null)
                cmd.Connection.Close();
            return result;
        }
        /// <summary>修改StateFlowStatus信息</summary>
        public override int Edit(Guid FlowIdx, string Condition, string Status)
        {
            SqlCommand cmd = Statement.InitCommand("UPDATE " + Statement.Owner + Statement.Qualifier + "StateFlowStatus SET FlowIdx=@FlowIdx,Condition=@Condition,Status=@Status WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@FlowIdx", SqlDbType.UniqueIdentifier).Value = FlowIdx;
            cmd.Parameters.AddWithValue("@Condition", SqlDbType.NVarChar).Value = Condition;
            cmd.Parameters.AddWithValue("@Status", SqlDbType.NVarChar).Value = Status;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        #endregion
    }
    #endregion

    /// <summary>
    /// 数据及操作控制层
    /// <seealso cref="Von.Web.Structs.OptionInfo"/>
    /// <seealso cref="Von.Web.Tasks.OptionTask"/>
    /// </summary>
    public class SqlOptionAccess : OptionAccess
    {
        #region "Option override Methods"
        /// <summary>根据主键 PK_OPTION 提取信息</summary>
        ///<param name="ID">序号</param>
        public override IDataReader GetByOPTION(string OptName)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [OptName],[OptKind],[OptInfo] FROM " + Statement.Owner + Statement.Qualifier + "Option WHERE OptName=@OptName", DBTrans);
            cmd.Parameters.AddWithValue("@OptName", SqlDbType.NVarChar).Value = OptName;
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>编辑参数值信息</summary>
        ///<param name="ID">序号</param>
        ///<param name="OptValues">参数值</param>
        public override string GetOptValues(string OptName)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT OptValues FROM " + Statement.Owner + Statement.Qualifier + "Option WHERE OptName=@OptName", DBTrans);
            cmd.Parameters.AddWithValue("@OptName", SqlDbType.NVarChar).Value = OptName;
            string result = Convert.ToString(cmd.ExecuteScalar());
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        /// <summary>编辑参数值信息</summary>
        public override int SetOptValues(string OptName, string OptValues)
        {
            SqlCommand cmd = Statement.InitCommand("UPDATE " + Statement.Owner + Statement.Qualifier + "Option SET OptValues=@OptValues WHERE OptName=@OptName", DBTrans);
            cmd.Parameters.AddWithValue("@OptName", SqlDbType.NVarChar).Value = OptName;
            cmd.Parameters.AddWithValue("@OptValues", SqlDbType.Text).Value = OptValues;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        /// <summary>提取 系统选项 列表</summary>
        public override IDataReader List()
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [OptName],[OptKind],[OptInfo] FROM " + Statement.Owner + Statement.Qualifier + "Option ", DBTrans);
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>添加Option信息</summary>
        /// <param name="ID">序号</param>
        /// <param name="OptName">参数名称</param>
        /// <param name="OptKind">参数类型</param>
        /// <param name="OptInfo">参数说明</param>
        public override int Add(string OptName, int OptKind, string OptInfo)
        {
            SqlCommand cmd = Statement.InitCommand("INSERT INTO " + Statement.Owner + Statement.Qualifier + "Option (OptName,OptKind,OptInfo)VALUES(@OptName,@OptKind,@OptInfo)", DBTrans);
            cmd.Parameters.AddWithValue("@OptName", SqlDbType.NVarChar).Value = OptName;
            cmd.Parameters.AddWithValue("@OptKind", SqlDbType.Int).Value = OptKind;
            cmd.Parameters.AddWithValue("@OptInfo", SqlDbType.NVarChar).Value = OptInfo;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        /// <summary>修改Option信息</summary>
        /// <param name="ID">序号</param>
        /// <param name="OptName">参数名称</param>
        /// <param name="OptKind">参数类型</param>
        /// <param name="OptInfo">参数说明</param>
        public override int Edit(string OptName, int OptKind, string OptInfo)
        {
            SqlCommand cmd = Statement.InitCommand("UPDATE " + Statement.Owner + Statement.Qualifier + "Option SET OptKind=@OptKind,OptInfo=@OptInfo WHERE OptName=@OptName", DBTrans);
            cmd.Parameters.AddWithValue("@OptName", SqlDbType.NVarChar).Value = OptName;
            cmd.Parameters.AddWithValue("@OptKind", SqlDbType.Int).Value = OptKind;
            cmd.Parameters.AddWithValue("@OptInfo", SqlDbType.NVarChar).Value = OptInfo;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        /// <summary>根据PK_OPTION删除Option信息</summary>
        public override int Del(string OptName)
        {
            SqlCommand cmd = Statement.InitCommand("DELETE FROM " + Statement.Owner + Statement.Qualifier + "Option WHERE OptName=@OptName", DBTrans);
            cmd.Parameters.AddWithValue("@OptName", SqlDbType.NVarChar).Value = OptName;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        #endregion
    }
    #endregion
    /// <summary>
    /// 数据及操作控制层
    /// <seealso cref="Von.Web.Structs.ServiceInfo"/>
    /// <seealso cref="Von.Web.Tasks.ServiceTask"/>
    /// </summary>
    public class SqlServiceAccess : ServiceAccess
    {
        #region "Service override Methods"
        /// <summary>根据主键 PK_Service 提取信息</summary>
        ///<param name="ID">序号</param>
        public override IDataReader GetByService(Guid ID)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [ID],[ServiceName],[InterKind],[Intervalue],[Necessary],[Status],[Param] FROM " + Statement.Owner + Statement.Qualifier + "Service WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.UniqueIdentifier).Value = ID;
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>添加Service信息</summary>
        /// <param name="ID">序号</param>
        /// <param name="ServiceName">服务名称</param>
        /// <param name="InterKind">间隔方式</param>
        /// <param name="Intervalue">间隔值</param>
        /// <param name="Necessary">必要性</param>
        /// <param name="Status">状态</param>
        /// <param name="Param">执行参数</param>
        public override int Save(Guid ID, string ServiceName, int InterKind, int Intervalue, bool Necessary, string Status, string Param)
        {
            SqlCommand cmd = Statement.InitCommand("if exists (select 1 from  Von_Service where  id = @ID) UPDATE " + Statement.Owner + Statement.Qualifier +
                "Service SET ServiceName = @ServiceName, InterKind = @InterKind, Intervalue = @Intervalue, Necessary = @Necessary, Status = @Status, Param = @Param WHERE ID = @ID " +
                "ELSE INSERT INTO " + Statement.Owner + Statement.Qualifier + "Service (ID,ServiceName,InterKind,Intervalue,Necessary,Status,Param)VALUES(@ID,@ServiceName,@InterKind,@Intervalue,@Necessary,@Status,@Param)", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.UniqueIdentifier).Value = ID;
            cmd.Parameters.AddWithValue("@ServiceName", SqlDbType.NVarChar).Value = ServiceName;
            cmd.Parameters.AddWithValue("@InterKind", SqlDbType.Int).Value = InterKind;
            cmd.Parameters.AddWithValue("@Intervalue", SqlDbType.Int).Value = Intervalue;
            cmd.Parameters.AddWithValue("@Necessary", SqlDbType.Bit).Value = Necessary;
            cmd.Parameters.AddWithValue("@Status", SqlDbType.NVarChar).Value = Status;
            cmd.Parameters.AddWithValue("@Param", SqlDbType.NText).Value = Param;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null)
                cmd.Connection.Close();
            return result;
        }
        #endregion
    }
    #region "主页广告信息类声明"
    /// <summary>
    /// 数据及操作控制层
    /// <seealso cref="Von.Web.Data.Structs.SliderInfo"/>
    /// <seealso cref="Von.Web.Data.Tasks.SliderTask"/>
    /// </summary>
    public class SqlSliderAccess : SliderAccess
    {
        #region "Slider override Methods"
        /// <summary>根据主键 PK_SLIDER 提取信息</summary>
        ///<param name="ID">序号</param>
        public override IDataReader GetBySLIDER(int ID)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [ID],[Kind],[Title],[Import],[Content],[Validate],[Linker],[DisplayOrder] FROM " + Statement.Owner + Statement.Qualifier + "Slider WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.Int).Value = ID;
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>提取 主页广告 列表</summary>
        public override IDataReader List(string Kind)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [ID],[Kind],[Title],[Import],[Content],[Validate],[Linker],[DisplayOrder] FROM " + Statement.Owner + Statement.Qualifier + "Slider WHERE " + (string.IsNullOrEmpty(Kind) ? "" : "Kind=@Kind AND ") + "[Validate]>GetDate() ORDER BY [Kind],DisplayOrder", DBTrans);
            if (!string.IsNullOrEmpty(Kind)) cmd.Parameters.AddWithValue("@Kind", SqlDbType.NVarChar).Value = Kind;
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>添加Slider信息</summary>
        /// <param name="ID">序号</param>
        /// <param name="Kind">类型</param>
        /// <param name="Title">名称</param>
        /// <param name="Import">引用资料</param>
        /// <param name="Content">内容</param>
        /// <param name="Validate">有效期</param>
        /// <param name="Linker">链接</param>
        public override int Add(string Kind, string Title, string Import, string Content, DateTime Validate, string Linker, int DisplayOrder)
        {
            SqlCommand cmd = Statement.InitCommand("INSERT INTO " + Statement.Owner + Statement.Qualifier + "Slider (Kind,Title,Import,Content,Validate,Linker,DisplayOrder)OUTPUT INSERTED.ID VALUES(@Kind,@Title,@Import,@Content,@Validate,@Linker,@DisplayOrder)", DBTrans);
            cmd.Parameters.AddWithValue("@Kind", SqlDbType.NVarChar).Value = Kind;
            cmd.Parameters.AddWithValue("@Title", SqlDbType.NVarChar).Value = Title;
            cmd.Parameters.AddWithValue("@Import", SqlDbType.NText).Value = Import;
            cmd.Parameters.AddWithValue("@Content", SqlDbType.NText).Value = Content;
            cmd.Parameters.AddWithValue("@Validate", SqlDbType.DateTime).Value = Validate;
            cmd.Parameters.AddWithValue("@Linker", SqlDbType.NVarChar).Value = Linker;
            cmd.Parameters.AddWithValue("@DisplayOrder", SqlDbType.Int).Value = DisplayOrder;
            int result = Convert.ToInt32(cmd.ExecuteScalar());
            if (DBTrans == null)
                cmd.Connection.Close();
            return result;
        }
        /// <summary>修改Slider信息</summary>
        /// <param name="ID">序号</param>
        /// <param name="Kind">类型</param>
        /// <param name="Title">名称</param>
        /// <param name="Import">引用资料</param>
        /// <param name="Content">内容</param>
        /// <param name="Validate">有效期</param>
        /// <param name="Linker">链接</param>
        public override int Edit(int ID, string Kind, string Title, string Import, string Content, DateTime Validate, string Linker, int DisplayOrder)
        {
            SqlCommand cmd = Statement.InitCommand("UPDATE " + Statement.Owner + Statement.Qualifier + "Slider SET Kind=@Kind,Title=@Title,Import=@Import,Content=@Content,Validate=@Validate,Linker=@Linker,DisplayOrder=@DisplayOrder WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.Int).Value = ID;
            cmd.Parameters.AddWithValue("@Kind", SqlDbType.NVarChar).Value = Kind;
            cmd.Parameters.AddWithValue("@Title", SqlDbType.NVarChar).Value = Title;
            cmd.Parameters.AddWithValue("@Import", SqlDbType.NText).Value = Import;
            cmd.Parameters.AddWithValue("@Content", SqlDbType.NText).Value = Content;
            cmd.Parameters.AddWithValue("@Validate", SqlDbType.DateTime).Value = Validate;
            cmd.Parameters.AddWithValue("@Linker", SqlDbType.NVarChar).Value = Linker;
            cmd.Parameters.AddWithValue("@DisplayOrder", SqlDbType.Int).Value = DisplayOrder;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        /// <summary>根据PK_SLIDER删除Slider信息</summary>
        public override int Del(int ID)
        {
            SqlCommand cmd = Statement.InitCommand("DELETE FROM " + Statement.Owner + Statement.Qualifier + "Slider WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.Int).Value = ID;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }

        /// <summary>编辑引用资料信息</summary>
        ///<param name="ID">序号</param>
        ///<param name="Import">引用资料</param>
        public override string GetImport(int ID)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT Import FROM " + Statement.Owner + Statement.Qualifier + "Slider WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.Int).Value = ID;
            string result = (string)cmd.ExecuteScalar();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        /// <summary>编辑引用资料信息</summary>
        public override int SetImport(int ID, string Import)
        {
            SqlCommand cmd = Statement.InitCommand("UPDATE " + Statement.Owner + Statement.Qualifier + "Slider SET Import=@Import WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@Import", SqlDbType.NText).Value = Import;
            cmd.Parameters.AddWithValue("@ID", SqlDbType.Int).Value = ID;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        /// <summary>编辑内容信息</summary>
        ///<param name="ID">序号</param>
        ///<param name="Content">内容</param>
        public override string GetContent(int ID)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT Content FROM " + Statement.Owner + Statement.Qualifier + "Slider WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.Int).Value = ID;
            string result = (string)cmd.ExecuteScalar();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        /// <summary>编辑内容信息</summary>
        public override int SetContent(int ID, string Content)
        {
            SqlCommand cmd = Statement.InitCommand("UPDATE " + Statement.Owner + Statement.Qualifier + "Slider SET Content=@Content WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@Content", SqlDbType.NText).Value = Content;
            cmd.Parameters.AddWithValue("@ID", SqlDbType.Int).Value = ID;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        /// <summary>查询 主页广告 列表</summary>
        public override IDataReader Search(JObject ConditionJson)
        {
            SqlCommand cmd = Statement.InitCommand("", DBTrans);
            string whereSql = GereralSearchSql(ConditionJson, addParameter);
            cmd.CommandText = "SELECT [ID],[Kind],[Title],[Validate],[Linker],[DisplayOrder] FROM " + Statement.Owner + Statement.Qualifier + "Slider" + (whereSql == "" ? "" : " WHERE " + whereSql);
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
            void addParameter(string key, object val)
            {
                cmd.Parameters.AddWithValue("@" + key, val);
            }
        }
        #endregion
    }
    #endregion
    #region "文本文档分类信息类声明"
    /// <summary>
    /// 数据及操作控制层
    /// <seealso cref="Von.Web.Structs.HtmlCatalogInfo"/>
    /// <seealso cref="Von.Web.Tasks.HtmlCatalogTask"/>
    /// </summary>
    public class SqlHtmlCatalogAccess : HtmlCatalogAccess
    {
        #region "HtmlCatalog override Methods"
        /// <summary>根据主键 PK_HtmlCatalog 提取信息</summary>
        ///<param name="ID">序号</param>
        public override IDataReader GetByHtmlCatalog(int ID)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [ID],[CatalogName],[PID],[Icon],[DisplayOrder] FROM " + Statement.Owner + Statement.Qualifier + "HtmlCatalog WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.Int).Value = ID;
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>提取 文本文档分类 列表</summary>
        public override IDataReader List()
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [ID],[CatalogName],[PID],[Icon],[DisplayOrder] FROM " + Statement.Owner + Statement.Qualifier + "HtmlCatalog ", DBTrans);
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>根据主键 IDX_HtmlCatalog 提取信息</summary>
        /// <param name="PID">父级序号</param>
        /// <param name="DisplayOrder">显示顺序</param>
        public override IDataReader ListByPID(int PID)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [ID],[CatalogName],[PID],[Icon],[DisplayOrder] FROM " + Statement.Owner + Statement.Qualifier + "HtmlCatalog WHERE PID=@PID ORDER BY DisplayOrder", DBTrans);
            cmd.Parameters.AddWithValue("@PID", SqlDbType.Int).Value = PID;
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>移动HtmlCatalog显示顺序</summary>
        public override int Move(int ID, int newOrder)
        {
            SqlCommand cmd = Statement.InitCommand("MOVE_HtmlCatalog", DBTrans);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@ID", SqlDbType.Int).Value = ID;
            cmd.Parameters.AddWithValue("@NewOrder", SqlDbType.Int).Value = newOrder;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        /// <summary>添加HtmlCatalog信息</summary>
        /// <param name="ID">序号</param>
        /// <param name="CatalogName">分类名称</param>
        /// <param name="PID">父级序号</param>
        /// <param name="Icon">图标</param>
        /// <param name="DisplayOrder">显示顺序</param>
        public override int Add(string CatalogName, int PID, string Icon, int DisplayOrder)
        {
            SqlCommand cmd = Statement.InitCommand("INSERT INTO " + Statement.Owner + Statement.Qualifier + "HtmlCatalog (CatalogName,PID,Icon,DisplayOrder)OUTPUT INSERTED.ID VALUES(@CatalogName,@PID,@Icon,@DisplayOrder)", DBTrans);
            cmd.Parameters.AddWithValue("@CatalogName", SqlDbType.NVarChar).Value = CatalogName;
            cmd.Parameters.AddWithValue("@PID", SqlDbType.Int).Value = PID;
            cmd.Parameters.AddWithValue("@Icon", SqlDbType.NVarChar).Value = Icon;
            cmd.Parameters.AddWithValue("@DisplayOrder", SqlDbType.Int).Value = DisplayOrder;
            int result = Convert.ToInt32(cmd.ExecuteScalar());
            if (DBTrans == null)
                cmd.Connection.Close();
            return result;
        }
        /// <summary>修改HtmlCatalog信息</summary>
        /// <param name="ID">序号</param>
        /// <param name="CatalogName">分类名称</param>
        /// <param name="PID">父级序号</param>
        /// <param name="Icon">图标</param>
        /// <param name="DisplayOrder">显示顺序</param>
        public override int Edit(int ID, string CatalogName, int PID, string Icon, int DisplayOrder)
        {
            SqlCommand cmd = Statement.InitCommand("UPDATE " + Statement.Owner + Statement.Qualifier + "HtmlCatalog SET CatalogName=@CatalogName,PID=@PID,Icon=@Icon,DisplayOrder=@DisplayOrder WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.Int).Value = ID;
            cmd.Parameters.AddWithValue("@CatalogName", SqlDbType.NVarChar).Value = CatalogName;
            cmd.Parameters.AddWithValue("@PID", SqlDbType.Int).Value = PID;
            cmd.Parameters.AddWithValue("@Icon", SqlDbType.NVarChar).Value = Icon;
            cmd.Parameters.AddWithValue("@DisplayOrder", SqlDbType.Int).Value = DisplayOrder;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        /// <summary>根据PK_HtmlCatalog删除HtmlCatalog信息</summary>
        public override int Del(int ID)
        {
            SqlCommand cmd = Statement.InitCommand("DELETE FROM " + Statement.Owner + Statement.Qualifier + "HtmlCatalog WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.Int).Value = ID;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        /// <summary>
        /// 根据名称查找到当前目录
        /// </summary>
        public override IDataReader FindHtmlCatalog(int PID, string name)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [ID],[CatalogName],[PID],[Icon],[DisplayOrder] FROM " + Statement.Owner + Statement.Qualifier + "HtmlCatalog WHERE PID=@PID AND CatalogName=@CatalogName", DBTrans);
            cmd.Parameters.AddWithValue("@PID", SqlDbType.Int).Value = PID;
            cmd.Parameters.AddWithValue("@CatalogName", SqlDbType.NVarChar).Value = name;
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        #endregion
    }
    #endregion
    #region "文本内容信息类声明"
    /// <summary>
    /// 数据及操作控制层
    /// <seealso cref="Von.Web.Structs.HtmlContentInfo"/>
    /// <seealso cref="Von.Web.Tasks.HtmlContentTask"/>
    /// </summary>
    public class SqlHtmlContentAccess : HtmlContentAccess
    {
        #region "HtmlContent override Methods"
        /// <summary>根据主键 PK_HtmlContent 提取信息</summary>
        ///<param name="ID">序号</param>
        public override IDataReader GetByHtmlContent(int ID)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [ID],[HtmlName],[Status],[Title],[Tags],[Keyword],[Autor],[Src],[Linker],[Publishedate],[CatalogIdx],[BrowserCount] FROM " + Statement.Owner + Statement.Qualifier + "HtmlContent WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.Int).Value = ID;
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>编辑摘要信息</summary>
        ///<param name="ID">序号</param>
        ///<param name="Summary">摘要</param>
        public override string GetSummary(int ID)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT Summary FROM " + Statement.Owner + Statement.Qualifier + "HtmlContent WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.Int).Value = ID;
            string result = Convert.ToString(cmd.ExecuteScalar());
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        /// <summary>编辑摘要信息</summary>
        public override int SetSummary(int ID, string Summary)
        {
            SqlCommand cmd = Statement.InitCommand("UPDATE " + Statement.Owner + Statement.Qualifier + "HtmlContent SET Summary=@Summary WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@Summary", SqlDbType.NText).Value = Summary;
            cmd.Parameters.AddWithValue("@ID", SqlDbType.Int).Value = ID;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        /// <summary>编辑正文信息</summary>
        ///<param name="ID">序号</param>
        ///<param name="Content">正文</param>
        public override string GetContent(int ID)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT Content FROM " + Statement.Owner + Statement.Qualifier + "HtmlContent WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.Int).Value = ID;
            string result = Convert.ToString(cmd.ExecuteScalar());
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        /// <summary>编辑正文信息</summary>
        public override int SetContent(int ID, string Content)
        {
            SqlCommand cmd = Statement.InitCommand("UPDATE " + Statement.Owner + Statement.Qualifier + "HtmlContent SET Content=@Content WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@Content", SqlDbType.NText).Value = Content;
            cmd.Parameters.AddWithValue("@ID", SqlDbType.Int).Value = ID;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        /// <summary>提取 文本内容 列表</summary>
        public override IDataReader List()
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [ID],[HtmlName],[Status],[Title],[Tags],[Keyword],[Autor],[Src],[Linker],[Publishedate],[CatalogIdx],[BrowserCount] FROM " + Statement.Owner + Statement.Qualifier + "HtmlContent WHERE Status<>'删除'", DBTrans);
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>根据外键 FK_CONTENT_REF_HTMLCATALOG 提取信息</summary>
        public override IDataReader ListByCONTENT_REF_HTMLCATALOG(int CatalogIdx, int cnt, string Status)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT " + (cnt > 0 ? "TOP " + cnt.ToString() : "") + " [ID],[HtmlName],[Status],[Title],[Tags],[Keyword],[Autor],[Src],[Linker],[Publishedate],[CatalogIdx],[BrowserCount] FROM " + Statement.Owner + Statement.Qualifier + "HtmlContent WHERE CatalogIdx=@CatalogIdx AND " + (string.IsNullOrEmpty(Status) ? "Status<>'删除'" : "Status='" + Status + "'") + " ORDER BY Publishedate DESC", DBTrans);
            cmd.Parameters.AddWithValue("@CatalogIdx", SqlDbType.Int).Value = CatalogIdx;
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>添加HtmlContent信息</summary>
        /// <param name="ID">序号</param>
        /// <param name="HtmlName">文档名称</param>
        /// <param name="Status">状态</param>
        /// <param name="Title">标题</param>
        /// <param name="Tags">标签</param>
        /// <param name="Keyword">关键词</param>
        /// <param name="Autor">作者</param>
        /// <param name="Src">来源</param>
        /// <param name="Linker">链接</param>
        /// <param name="Publishedate">发布时间</param>
        /// <param name="CatalogIdx">所属分类</param>
        /// <param name="BrowserCount">浏览次数</param>
        public override int Add(string HtmlName, string Title, string Tags, string Keyword, string Autor, string Src, string Linker, int CatalogIdx)
        {
            SqlCommand cmd = Statement.InitCommand("INSERT INTO " + Statement.Owner + Statement.Qualifier + "HtmlContent (HtmlName,Status,Title,Tags,Keyword,Autor,Src,Linker,Publishedate,CatalogIdx,BrowserCount)OUTPUT INSERTED.ID VALUES(@HtmlName,@Status,@Title,@Tags,@Keyword,@Autor,@Src,@Linker,@Publishedate,@CatalogIdx,@BrowserCount)", DBTrans);
            cmd.Parameters.AddWithValue("@HtmlName", SqlDbType.NVarChar).Value = HtmlName;
            cmd.Parameters.AddWithValue("@Status", SqlDbType.NVarChar).Value = "编辑";
            cmd.Parameters.AddWithValue("@Title", SqlDbType.NVarChar).Value = Title;
            cmd.Parameters.AddWithValue("@Tags", SqlDbType.NVarChar).Value = Tags;
            cmd.Parameters.AddWithValue("@Keyword", SqlDbType.NVarChar).Value = Keyword;
            cmd.Parameters.AddWithValue("@Autor", SqlDbType.NVarChar).Value = Autor;
            cmd.Parameters.AddWithValue("@Src", SqlDbType.NVarChar).Value = Src;
            cmd.Parameters.AddWithValue("@Linker", SqlDbType.NVarChar).Value = Linker;
            cmd.Parameters.AddWithValue("@Publishedate", SqlDbType.DateTime).Value = Von.Library.Consts.MinDBDate;
            cmd.Parameters.AddWithValue("@CatalogIdx", SqlDbType.Int).Value = CatalogIdx;
            cmd.Parameters.AddWithValue("@BrowserCount", SqlDbType.Int).Value = 0;
            int result = Convert.ToInt32(cmd.ExecuteScalar());
            if (DBTrans == null)
                cmd.Connection.Close();
            return result;
        }
        /// <summary>修改HtmlContent信息</summary>
        /// <param name="ID">序号</param>
        /// <param name="HtmlName">文档名称</param>
        /// <param name="Status">状态</param>
        /// <param name="Title">标题</param>
        /// <param name="Tags">标签</param>
        /// <param name="Keyword">关键词</param>
        /// <param name="Autor">作者</param>
        /// <param name="Src">来源</param>
        /// <param name="Linker">链接</param>
        /// <param name="Publishedate">发布时间</param>
        /// <param name="CatalogIdx">所属分类</param>
        /// <param name="BrowserCount">浏览次数</param>
        public override int Edit(int ID, string HtmlName, string Title, string Tags, string Keyword, string Autor, string Src, string Linker)
        {
            SqlCommand cmd = Statement.InitCommand("UPDATE " + Statement.Owner + Statement.Qualifier + "HtmlContent SET HtmlName=@HtmlName,Title=@Title,Tags=@Tags,Keyword=@Keyword,Autor=@Autor,Src=@Src,Linker=@Linker WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.Int).Value = ID;
            cmd.Parameters.AddWithValue("@HtmlName", SqlDbType.NVarChar).Value = HtmlName;
            cmd.Parameters.AddWithValue("@Title", SqlDbType.NVarChar).Value = Title;
            cmd.Parameters.AddWithValue("@Tags", SqlDbType.NVarChar).Value = Tags;
            cmd.Parameters.AddWithValue("@Keyword", SqlDbType.NVarChar).Value = Keyword;
            cmd.Parameters.AddWithValue("@Autor", SqlDbType.NVarChar).Value = Autor;
            cmd.Parameters.AddWithValue("@Src", SqlDbType.NVarChar).Value = Src;
            cmd.Parameters.AddWithValue("@Linker", SqlDbType.NVarChar).Value = Linker;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        /// <summary>根据PK_HtmlContent删除HtmlContent信息</summary>
        public override int Del(int ID)
        {
            SqlCommand cmd = Statement.InitCommand("UPDATE " + Statement.Owner + Statement.Qualifier + "HtmlContent SET Status=@Status,Publishedate=@Publishedate WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.Int).Value = ID;
            cmd.Parameters.AddWithValue("@Status", SqlDbType.NVarChar).Value = "删除";
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        /// <summary>根据FK_CONTENT_REF_HTMLCATALOG删除HtmlContent信息</summary>
        public override int DelCatalog(int CatalogIdx)
        {
            SqlCommand cmd = Statement.InitCommand("UPDATE " + Statement.Owner + Statement.Qualifier + "HtmlContent SET Status=@Status,Publishedate=@Publishedate WHERE CatalogIdx=@CatalogIdx", DBTrans);
            cmd.Parameters.AddWithValue("@CatalogIdx", SqlDbType.Int).Value = CatalogIdx;
            cmd.Parameters.AddWithValue("@Status", SqlDbType.NVarChar).Value = "删除";
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }

        public override int Publish(int ID)
        {
            SqlCommand cmd = Statement.InitCommand("UPDATE " + Statement.Owner + Statement.Qualifier + "HtmlContent SET Status=@Status,Publishedate=@Publishedate WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.Int).Value = ID;
            cmd.Parameters.AddWithValue("@Status", SqlDbType.NVarChar).Value = "发布";
            cmd.Parameters.AddWithValue("@Publishedate", SqlDbType.DateTime).Value = DateTime.Now;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }

        public override IDataReader FindHtmlContent(int PID, string name)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [ID],[HtmlName],[Status],[Title],[Tags],[Keyword],[Autor],[Src],[Linker],[Publishedate],[CatalogIdx],[BrowserCount] FROM " + Statement.Owner + Statement.Qualifier + "HtmlContent WHERE CatalogIdx=@PID AND HtmlName=@HtmlName AND Status<>'删除'", DBTrans);
            cmd.Parameters.AddWithValue("@PID", SqlDbType.Int).Value = PID;
            cmd.Parameters.AddWithValue("@HtmlName", SqlDbType.Int).Value = name;
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        #endregion
    }
    #endregion
    #region "评论信息类声明"
    /// <summary>
    /// 数据及操作控制层
    /// <seealso cref="Von.Web.Structs.CommentInfo"/>
    /// <seealso cref="Von.Web.Tasks.CommentTask"/>
    /// </summary>
    public class SqlCommentAccess : CommentAccess
    {
        #region "Comment override Methods"
        /// <summary>根据主键 PK_Comment 提取信息</summary>
        ///<param name="ID">序号</param>
        public override IDataReader GetByComment(int ID)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [ID],[Kind],[LinkIdx],[Evaluation],[Publishedate],[Publisher],[Email],[Concern],[Support],[Oppose],[ReplyDate],[Replyer],[Content],[ReplyContent] FROM " + Statement.Owner + Statement.Qualifier + "Comment WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.Int).Value = ID;
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>根据主键 IDX_Comment 提取信息</summary>
        /// <param name="Kind">评论文档类型</param>
        /// <param name="LinkIdx">文档序号</param>
        public override IDataReader ListByComment(string Kind, string LinkIdx)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [ID],[Kind],[LinkIdx],[Evaluation],[Publishedate],[Publisher],[Email],[Concern],[Support],[Oppose],[ReplyDate],[Replyer],[Content],[ReplyContent] FROM " + Statement.Owner + Statement.Qualifier + "Comment WHERE Kind=@Kind AND LinkIdx=@LinkIdx", DBTrans);
            cmd.Parameters.AddWithValue("@Kind", SqlDbType.NVarChar).Value = Kind;
            cmd.Parameters.AddWithValue("@LinkIdx", SqlDbType.NVarChar).Value = LinkIdx;
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>添加Comment信息</summary>
        /// <param name="ID">序号</param>
        /// <param name="Kind">评论文档类型</param>
        /// <param name="LinkIdx">文档序号</param>
        /// <param name="Evaluation">点评值</param>
        /// <param name="Publishedate">点评日期</param>
        /// <param name="Publisher">点评用户</param>
        /// <param name="Email">回复邮箱</param>
        /// <param name="Concern">关注</param>
        /// <param name="Support">支持</param>
        /// <param name="Oppose">差评</param>
        /// <param name="ReplyDate">回复日期</param>
        /// <param name="Replyer">回复人</param>
        public override int Add(string Kind, string LinkIdx, int Evaluation, Guid Publisher, string Email, bool Concern, bool Support, bool Oppose, string Content)
        {
            SqlCommand cmd = Statement.InitCommand("INSERT INTO " + Statement.Owner + Statement.Qualifier + "Comment (Kind,LinkIdx,Evaluation,Publishedate,Publisher,Email,Concern,Support,Oppose,Content)OUTPUT INSERTED.ID VALUES(@Kind,@LinkIdx,@Evaluation,GetDate(),@Publisher,@Email,@Concern,@Support,@Oppose,@Content)", DBTrans);
            cmd.Parameters.AddWithValue("@Kind", SqlDbType.NVarChar).Value = Kind;
            cmd.Parameters.AddWithValue("@LinkIdx", SqlDbType.NVarChar).Value = LinkIdx;
            cmd.Parameters.AddWithValue("@Evaluation", SqlDbType.Int).Value = Evaluation;
            cmd.Parameters.AddWithValue("@Publisher", SqlDbType.UniqueIdentifier).Value = Publisher;
            cmd.Parameters.AddWithValue("@Email", SqlDbType.NVarChar).Value = Email;
            cmd.Parameters.AddWithValue("@Concern", SqlDbType.Bit).Value = Concern;
            cmd.Parameters.AddWithValue("@Support", SqlDbType.Bit).Value = Support;
            cmd.Parameters.AddWithValue("@Oppose", SqlDbType.Bit).Value = Oppose;
            cmd.Parameters.AddWithValue("@Content", SqlDbType.NText).Value = Content;
            int result = Convert.ToInt32(cmd.ExecuteScalar());
            if (DBTrans == null)
                cmd.Connection.Close();
            return result;
        }
        /// <summary>根据PK_Comment删除Comment信息</summary>
        public override int Del(int ID)
        {
            SqlCommand cmd = Statement.InitCommand("DELETE FROM " + Statement.Owner + Statement.Qualifier + "Comment WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.Int).Value = ID;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }

        public override int ReplyComment(int ID, Guid replyer, string replyContent)
        {
            SqlCommand cmd = Statement.InitCommand("UPDATE " + Statement.Owner + Statement.Qualifier + "Comment SET ReplyDate=GetDate(),Replyer=@Replyer,ReplyContent=@ReplyContent WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.Int).Value = ID;
            cmd.Parameters.AddWithValue("@Replyer", SqlDbType.UniqueIdentifier).Value = replyer;
            cmd.Parameters.AddWithValue("@ReplyContent", SqlDbType.NText).Value = replyContent;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        #endregion
    }
    #endregion
    #region "照片资源信息类声明"
    /// <summary>
    /// 数据及操作控制层
    /// <seealso cref="Von.Web.Structs.ImageInfo"/>
    /// <seealso cref="Von.Web.Tasks.ImageTask"/>
    /// </summary>
    public class SqlImageAccess : ImageAccess
    {
        #region "Image override Methods"
        /// <summary>根据主键 PK_Image 提取信息</summary>
        ///<param name="ID">序号</param>
        public override IDataReader GetByImage(Guid ID)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [ID],[Kind],[Code],[ImageName],[Ext] FROM " + Statement.Owner + Statement.Qualifier + "Image WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.UniqueIdentifier).Value = ID;
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>编辑图片信息</summary>
        ///<param name="ID">序号</param>
        ///<param name="Img">图片</param>
        public override byte[] GetImg(Guid ID)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT Img FROM " + Statement.Owner + Statement.Qualifier + "Image WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.UniqueIdentifier).Value = ID;
            byte[] b = (byte[])cmd.ExecuteScalar();
            cmd.Connection.Close();
            return b;
        }
        /// <summary>编辑图片信息</summary>
        public override int SetImg(Guid ID, Stream Img)
        {
            byte[] img = new byte[Img.Length];
            Img.Read(img, 0, img.Length);
            SqlCommand cmd = Statement.InitCommand("UPDATE " + Statement.Owner + Statement.Qualifier + "Image SET Img=@Img WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.UniqueIdentifier).Value = ID;
            cmd.Parameters.Add("@Img", SqlDbType.Image).Value = img;
            int cnt = cmd.ExecuteNonQuery();
            cmd.Connection.Close();
            return cnt;
        }
        /// <summary>提取 照片资源 列表</summary>
        public override IDataReader List()
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [ID],[Kind],[Code],[ImageName],[Ext] FROM " + Statement.Owner + Statement.Qualifier + "Image ", DBTrans);
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>根据主键 IDX_Image 提取信息</summary>
        /// <param name="Kind">资源类型</param>
        /// <param name="Code">编码</param>
        public override IDataReader GetByImage(string Kind, string Code)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [ID],[Kind],[Code],[ImageName],[Ext] FROM " + Statement.Owner + Statement.Qualifier + "Image WHERE Kind=@Kind AND Code=@Code", DBTrans);
            cmd.Parameters.AddWithValue("@Kind", SqlDbType.NVarChar).Value = Kind;
            cmd.Parameters.AddWithValue("@Code", SqlDbType.VarChar).Value = Code;
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>添加Image信息</summary>
        /// <param name="ID">序号</param>
        /// <param name="Kind">资源类型</param>
        /// <param name="Code">编码</param>
        /// <param name="ImageName">资源名称</param>
        /// <param name="Ext">图片类型</param>
        public override int Add(Guid ID, string Kind, string Code, string ImageName, string Ext)
        {
            SqlCommand cmd = Statement.InitCommand("INSERT INTO " + Statement.Owner + Statement.Qualifier + "Image (ID,Kind,Code,ImageName,Ext)VALUES(@ID,@Kind,@Code,@ImageName,@Ext)", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.UniqueIdentifier).Value = ID;
            cmd.Parameters.AddWithValue("@Kind", SqlDbType.NVarChar).Value = Kind;
            cmd.Parameters.AddWithValue("@Code", SqlDbType.VarChar).Value = Code;
            cmd.Parameters.AddWithValue("@ImageName", SqlDbType.NVarChar).Value = ImageName;
            cmd.Parameters.AddWithValue("@Ext", SqlDbType.VarChar).Value = Ext;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null)
                cmd.Connection.Close();
            return result;
        }
        /// <summary>修改Image信息</summary>
        /// <param name="ID">序号</param>
        /// <param name="Kind">资源类型</param>
        /// <param name="Code">编码</param>
        /// <param name="ImageName">资源名称</param>
        /// <param name="Ext">图片类型</param>
        public override int Edit(Guid ID, string Kind, string Code, string ImageName, string Ext)
        {
            SqlCommand cmd = Statement.InitCommand("UPDATE " + Statement.Owner + Statement.Qualifier + "Image SET Kind=@Kind,Code=@Code,ImageName=@ImageName,Ext=@Ext WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.UniqueIdentifier).Value = ID;
            cmd.Parameters.AddWithValue("@Kind", SqlDbType.NVarChar).Value = Kind;
            cmd.Parameters.AddWithValue("@Code", SqlDbType.VarChar).Value = Code;
            cmd.Parameters.AddWithValue("@ImageName", SqlDbType.NVarChar).Value = ImageName;
            cmd.Parameters.AddWithValue("@Ext", SqlDbType.VarChar).Value = Ext;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        /// <summary>根据PK_Image删除Image信息</summary>
        public override int Del(Guid ID)
        {
            SqlCommand cmd = Statement.InitCommand("DELETE FROM " + Statement.Owner + Statement.Qualifier + "Image WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@ID", SqlDbType.UniqueIdentifier).Value = ID;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        #endregion
    }
    #endregion
    #region "系统日志信息数据库访问基类声明"
    /// <summary>
    /// 数据及操作控制层
    /// <seealso cref="VonPortal.Web.Structs.LogInfo"/>
    /// <seealso cref="VonPortal.Web.Tasks.LogTask"/>
    /// </summary>
    public class SqlLogAccess : LogAccess
    {
        #region "Log override Methods"
        /// <summary>提取 系统日志 列表</summary>
        public override IDataReader List()
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [LogTime],[EventName],[Level],[Content],[Operator] FROM " + Statement.Owner + Statement.Qualifier + "Log ", DBTrans);
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>根据主键 IDX_Log 提取信息</summary>
        /// <param name="LogTime">时间</param>
        public override IDataReader ListByLog(DateTime LogTime)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [LogTime],[EventName],[Level],[Content],[Operator] FROM " + Statement.Owner + Statement.Qualifier + "Log WHERE LogTime=@LogTime", DBTrans);
            cmd.Parameters.AddWithValue("@LogTime", SqlDbType.DateTime).Value = LogTime;
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>查询 系统日志 列表</summary>
        public override IDataReader Search(JObject ConditionJson)
        {
            SqlCommand cmd = Statement.InitCommand("", DBTrans);
            string whereSql = GereralSearchSql(ConditionJson, addParameter);
            cmd.CommandText = "SELECT [LogTime],[EventName],[Level],[Content],[Operator] FROM " + Statement.Owner + Statement.Qualifier + "Log" + (whereSql == "" ? "" : " WHERE " + whereSql);
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
            void addParameter(string key, object val)
            {
                cmd.Parameters.AddWithValue("@" + key, val);
            }
        }
        /// <summary>添加Log信息</summary>
        /// <param name="LogTime">时间</param>
        /// <param name="EventNsmr">事件</param>
        /// <param name="Level">等级</param>
        /// <param name="Content">内容</param>
        /// <param name="Operator">操作人</param>
        public override int Add(DateTime LogTime, string EventName, int Level, string Content, string Operator)
        {
            SqlCommand cmd = Statement.InitCommand("INSERT INTO " + Statement.Owner + Statement.Qualifier + "Log (LogTime,EventName,Level,Content,Operator)VALUES(@LogTime,@EventName,@Level,@Content,@Operator)", DBTrans);
            cmd.Parameters.AddWithValue("@LogTime", SqlDbType.DateTime).Value = LogTime;
            cmd.Parameters.AddWithValue("@EventName", SqlDbType.NVarChar).Value = EventName;
            cmd.Parameters.AddWithValue("@Level", SqlDbType.Int).Value = Level;
            cmd.Parameters.AddWithValue("@Content", SqlDbType.NVarChar).Value = Content;
            cmd.Parameters.AddWithValue("@Operator", SqlDbType.NVarChar).Value = Operator;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null)
                cmd.Connection.Close();
            return result;
        }
        /// <summary>修改Log信息</summary>
        /// <param name="LogTime">时间</param>
        /// <param name="EventNsmr">事件</param>
        /// <param name="Level">等级</param>
        /// <param name="Content">内容</param>
        /// <param name="Operator">操作人</param>
        public override int Edit(DateTime LogTime, string EventName, int Level, string Content, string Operator)
        {
            SqlCommand cmd = Statement.InitCommand("UPDATE " + Statement.Owner + Statement.Qualifier + "Log SET LogTime=@LogTime,EventName=@EventName,Level=@Level,Content=@Content,Operator=@Operator WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@LogTime", SqlDbType.DateTime).Value = LogTime;
            cmd.Parameters.AddWithValue("@EventName", SqlDbType.NVarChar).Value = EventName;
            cmd.Parameters.AddWithValue("@Level", SqlDbType.Int).Value = Level;
            cmd.Parameters.AddWithValue("@Content", SqlDbType.NVarChar).Value = Content;
            cmd.Parameters.AddWithValue("@Operator", SqlDbType.NVarChar).Value = Operator;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        /// <summary>
        /// 清除数据库中系统日志
        /// </summary>
        /// <param name="firstDate"></param>
        /// <returns></returns>
        public override int Delete(DateTime firstDate)
        {
            SqlCommand cmd = Statement.InitCommand("DELETE " + Statement.Owner + Statement.Qualifier + "Log WHERE LogTime<@LogTime", DBTrans);
            cmd.Parameters.AddWithValue("@LogTime", SqlDbType.DateTime).Value = firstDate;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        #endregion
    }
    #endregion
    #region "行政区划信息类声明"
    /// <summary>
    /// 数据及操作控制层
    /// <seealso cref="Security.Web.Structs.AdministrativeDistrictInfo"/>
    /// <seealso cref="Security.Web.Tasks.AdministrativeDistrictTask"/>
    /// </summary>
    public class SqlAdministrativeDistrictAccess : AdministrativeDistrictAccess
    {
        #region "AdministrativeDistrict override Methods"
        /// <summary>根据主键 PK_AdministrativeDistrict 提取信息</summary>
        ///<param name="ID">序号</param>
        public override IDataReader GetByAdministrativeDistrict(string Code)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [Code],[ADName],[Level] FROM " + Statement.Owner + Statement.Qualifier + "AdministrativeDistrict WHERE Code=@Code", DBTrans);
            cmd.Parameters.AddWithValue("@Code", SqlDbType.VarChar).Value = Code;
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>提取 行政区划 列表</summary>
        public override IDataReader List(int level)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [Code],[ADName],[Level] FROM " + Statement.Owner + Statement.Qualifier + "AdministrativeDistrict WHERE [Level]=@Level", DBTrans);
            cmd.Parameters.AddWithValue("@Level", SqlDbType.Int).Value = level;
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>提取 行政区划 列表</summary>
        public override IDataReader List(string parentCode)
        {
            SqlCommand cmd = Statement.InitCommand("SELECT [Code],[ADName],[Level] FROM " + Statement.Owner + Statement.Qualifier + "AdministrativeDistrict WHERE Code LIKE @PCODE + '__'", DBTrans);
            cmd.Parameters.AddWithValue("@PCODE", SqlDbType.VarChar).Value = parentCode;
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        /// <summary>添加AdministrativeDistrict信息</summary>
        /// <param name="Code">区划编码</param>
        /// <param name="ADName">名称</param>
        /// <param name="Level">层级</param>
        public override int Add(string Code, string ADName, int Level)
        {
            SqlCommand cmd = Statement.InitCommand("INSERT INTO " + Statement.Owner + Statement.Qualifier + "AdministrativeDistrict (Code,ADName,Level)VALUES(@Code,@ADName,@Level)", DBTrans);
            cmd.Parameters.AddWithValue("@Code", SqlDbType.VarChar).Value = Code;
            cmd.Parameters.AddWithValue("@ADName", SqlDbType.NVarChar).Value = ADName;
            cmd.Parameters.AddWithValue("@Level", SqlDbType.Int).Value = Level;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null)
                cmd.Connection.Close();
            return result;
        }
        /// <summary>修改AdministrativeDistrict信息</summary>
        /// <param name="Code">区划编码</param>
        /// <param name="ADName">名称</param>
        /// <param name="Level">层级</param>
        public override int Edit(string Code, string ADName, int Level)
        {
            SqlCommand cmd = Statement.InitCommand("UPDATE " + Statement.Owner + Statement.Qualifier + "AdministrativeDistrict SET Code=@Code,ADName=@ADName,Level=@Level WHERE ID=@ID", DBTrans);
            cmd.Parameters.AddWithValue("@Code", SqlDbType.VarChar).Value = Code;
            cmd.Parameters.AddWithValue("@ADName", SqlDbType.NVarChar).Value = ADName;
            cmd.Parameters.AddWithValue("@Level", SqlDbType.Int).Value = Level;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }
        /// <summary>根据PK_AdministrativeDistrict删除AdministrativeDistrict信息</summary>
        public override int Del(string Code)
        {
            SqlCommand cmd = Statement.InitCommand("DELETE FROM " + Statement.Owner + Statement.Qualifier + "AdministrativeDistrict WHERE Code=@Code", DBTrans);
            cmd.Parameters.AddWithValue("@Code", SqlDbType.VarChar).Value = Code;
            int result = cmd.ExecuteNonQuery();
            if (DBTrans == null) cmd.Connection.Close();
            return result;
        }

        /// <summary>查询 行政区划 列表</summary>
        public override IDataReader Search(JObject ConditionJson)
        {
            SqlCommand cmd = Statement.InitCommand("", DBTrans);
            string whereSql = GereralSearchSql(ConditionJson, addParameter);
            cmd.CommandText = "SELECT [Code],[ADName],[Level] FROM " + Statement.Owner + Statement.Qualifier + "AdministrativeDistrict" + (whereSql == "" ? "" : " WHERE " + whereSql);
            if (DBTrans != null) return cmd.ExecuteReader();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
            void addParameter(string key, object val)
            {
                cmd.Parameters.AddWithValue("@" + key, val);
            }
        }
        #endregion
    }
    #endregion
}